Spark library includes common tools for working with data in Go. It will be updated whenever I need new utils or someone wants to bring new ones.
Map function converts the given struct to a map[string]interface{}
, where the keys of the map are the field names and the values of the map the associated values of the fields. The default key string is the struct field name but can be changed in the struct field's tag value. The structs
key in the struct's field tag value is the key name.
s := struct {
Age int
Name string
}{
Age: 25,
Name: "John Doe",
}
m := structs.Map(s)
age := m["Age"]
name := m["Name"]
s := struct {
Age int `structs:"my-age"`
Name string `structs:"my-name"`
}{
Age: 25,
Name: "John Doe",
}
m := structs.Map(s)
age := m["my-age"]
name := m["my-name"]