Documentation ¶
Index ¶
- func Float32(from interface{}) (f float32, e error)
- func Float64(from interface{}) (f float64, e error)
- func Int(from interface{}) (i int, e error)
- func Int64(from interface{}) (i int64, e error)
- func String(from interface{}) (s string)
- func Struct(to interface{}, from map[string]interface{}, formats ...string) error
- func Uint(from interface{}) (u uint, e error)
- func Uint64(from interface{}) (u int64, e error)
- func Var(pto interface{}, from interface{}) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Struct ¶
Struct attempts to unmarshall the values in 'from' into the fields in the structure pointed to by 'target'. The field names are used as map keys. Optional format strings can be used to morph the field names into keys, eg "--%s" will map field "foo" to key "--foo". If more than one format is supplied, these will be tried in order until the first matching key is found. When coercing from string to any integer types, if the string ends with B|K|M|G|T (case-insensitive) then these will be interpreted as multipliers of 1, 1024, etc.
Example:
type x struct{ intslice []int boolval bool s string } mymap := map[string]interface{} { "--intslice": []string {"5", "12", "0.5k"}, "--boolval" : true, "-s" : "hello", } var myx x err := coerce.Struct(&myx, mymap, "--%s", "-%s") fmt.Println(err, myx) // <nil> {[5 12 512] true hello}
Note: coercing unexported fields uses 'unsafe' pointers
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.