Documentation ¶
Overview ¶
Package binding provide some common binder for binding http.Request data to strcut
Index ¶
- Variables
- func Auto(r *http.Request, obj any) (err error)
- func Bind(r *http.Request, obj any) error
- func DecodeUrlValues(values map[string][]string, ptr any, tagName string) error
- func DisableValidator()
- func MustBind(r *http.Request, obj any)
- func Register(name string, b Binder)
- func Remove(names ...string)
- func ResetValidator()
- func Validate(obj any) error
- type Binder
- type BinderFunc
- type DataValidator
- type FormBinder
- type HeaderBinder
- type JSONBinder
- type QueryBinder
- type XMLBinder
Constants ¶
This section is empty.
Variables ¶
var ( Form = FormBinder{FormTagName} Header = HeaderBinder{HeaderTagName} Query = QueryBinder{QueryTagName} JSON = JSONBinder{} XML = XMLBinder{} // Binders mapping Binders = map[string]Binder{ "xml": XML, "json": JSON, "query": Query, "form": Form, "header": Header, } )
build-in data binder
var DefaultMaxMemory int64 = 32 << 20 // 32 MB
DefaultMaxMemory for parse data form
var FormTagName = "form"
FormTagName for decode form data
var HeaderTagName = "header"
HeaderTagName for binding data
var QueryTagName = "query"
TagName for decode url.Values(form,query) data
Functions ¶
func Auto ¶
Auto bind request data to a ptr value
body, err := ioutil.ReadAll(c.Request().Body) if err != nil { c.Logger().Errorf("could not read request body: %v", err) } c.Set("request_body", body) // fix: can not read request body multiple times c.Request().Body = ioutil.NopCloser(bytes.NewReader(body))
func DecodeUrlValues ¶
DecodeUrlValues data to struct
Types ¶
type BinderFunc ¶
BinderFunc bind func, implement the Binder() interface
type DataValidator ¶
DataValidator interface
var Validator DataValidator = &stdValidator{}
Validator for validate bounded data
type FormBinder ¶
type FormBinder struct {
TagName string
}
FormBinder binding Form/url.Values data to struct
func (FormBinder) Bind ¶
func (b FormBinder) Bind(r *http.Request, ptr any) error
Bind Form data from http.Request
func (FormBinder) BindValues ¶
func (b FormBinder) BindValues(values url.Values, ptr any) error
BindValues data from url.Values
type HeaderBinder ¶
type HeaderBinder struct {
TagName string
}
HeaderBinder binding URL query data to struct
func (HeaderBinder) Bind ¶
func (b HeaderBinder) Bind(r *http.Request, ptr any) error
Bind Header data binding
func (HeaderBinder) BindValues ¶
func (b HeaderBinder) BindValues(headers map[string][]string, ptr any) error
BindValues data from headers
type JSONBinder ¶
type JSONBinder struct{}
JSONBinder binding JSON data to struct
func (JSONBinder) Bind ¶
func (JSONBinder) Bind(r *http.Request, ptr any) error
Bind JSON data from http.Request
type QueryBinder ¶
type QueryBinder struct {
TagName string
}
QueryBinder binding URL query data to struct
func (QueryBinder) Bind ¶
func (b QueryBinder) Bind(r *http.Request, ptr any) error
Bind Query data binder
func (QueryBinder) BindValues ¶
func (b QueryBinder) BindValues(values url.Values, ptr any) error
BindValues data from url.Values