You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
package binding
|
|
|
|
|
|
|
|
import (
|
|
|
|
"git.diulo.com/mogfee/kit/encoding"
|
|
|
|
"git.diulo.com/mogfee/kit/encoding/form"
|
|
|
|
"git.diulo.com/mogfee/kit/errors"
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
)
|
|
|
|
|
|
|
|
func BindQuery(vars url.Values, target any) error {
|
|
|
|
if err := encoding.GetCodec(form.Name).Unmarshal([]byte(vars.Encode()), target); err != nil {
|
|
|
|
return errors.BadRequest("CODEC", err.Error())
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
func BindForm(req *http.Request, target any) error {
|
|
|
|
if err := req.ParseForm(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := encoding.GetCodec(form.Name).Unmarshal([]byte(req.Form.Encode()), target); err != nil {
|
|
|
|
return errors.BadRequest("CODEC", err.Error())
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|