querer, Spanish, to want, to love, to wish, to like
Querer is a golang package for when you want to populate a struct based on URL query string values.
type params struct {
MinDOB time.Time `query:"min_dob"`
MaxDOB time.Time `query:"max_dob"`
MaxAge uint `query:"max_age"`
LastName string `query:"last_name"`
}
params := new(params)
err := UnmarshalQuery(params, req.URL.Query())
if err != nil {
...
}
...
This package currently supports:
- bool
- int
- uint
- float64
- string
- time.Time
If you have a need for more types, please open an issue or - even better - a pull request!
Embedded/anonymous structs are also supported. For example.
type baseParams struct {
Param1 int `query:"param_1"`
}
type params struct {
*baseParams
Param2 int `query:"param_2"`
}