a package for decode form's values into struct in Go
A Go package to decode HTTP form and query parameters. The only requirement is Go 1.12 or later.
go get github.com/monoculum/formam/v3maps, structs and slices.UnmarshalText() interface in values and keys of maps.map keys are string, int and variants, uint and variants, uintptr, float32, float64, bool, struct, custom types to one of the above types registered by function or UnmarshalText method, a pointer to one of the above typesinterface{} that has a map, struct or slice as value is accessible.time.Time with format 2006-01-02 by its UnmarshalText() method.url.URL.slice and array types without explicitly indicating an index.You can see the performance in formam-benchmark compared with ajg/form, gorilla/schema, go-playground/form and built-in/json.
. to access a struct field (e.g. struct.field1).[] to access tje specific slice/array index (e.g. struct.array[0]). It's not necessary to add an index to append data.[] to access map keys (e.g.. struct.map[es-ES]).
You can use the formam struct tag to ensure the form values are unmarshalled in the currect struct fields.
…Supported types in the destination struct are:
stringboolint, int8, int16, int32, int64uint, uint8, uint16, uint32, uint64float32, float64slice, arraystruct and struct anonymousmapinterface{}time.Timeurl.URLcustom types to one of the above typespointer to one of the above typesYou can umarshal data and map keys by implementing the encoding.TextUnmarshaler interface.
If the forms sends multiple values then only the first value is passed to UnmarshalText(), but if the name ends with [] then it's called for all values.
You can register a function for a custom type using the RegisterCustomType() method. This will work for any number of given fields or all fields with the given type.
Registered type have preference over the UnmarshalText method unless the PrefUnmarshalText option is used.
decoder.RegisterCustomType(func(vals []string) (interface{}, error) {
return time.Parse("2006-01-02", vals[0])
}, []interface{}{time.Time{}}, nil)…Version 2 is compatible with old syntax to access to maps (map.key), but brackets are the preferred way to access a map (map[key]).
No open issues yet, or sync has not completed.