Documentation
¶
Overview ¶
Package binder is used to bind a value to the http request.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Binder ¶
type Binder interface { // Bind parses the data from http.Request to dst. // // Notice: dst must be a non-nil pointer. Bind(dst interface{}, req *http.Request) error }
Binder is used to bind the data to the http request.
var ( DefaultMuxBinder = NewMuxBinder() DefaultQueryBinder Binder = BindFunc(func(dst interface{}, r *http.Request) error { return binder.BindStructToURLValues(dst, "query", r.URL.Query()) }) DefaultHeaderBinder Binder = BindFunc(func(dst interface{}, r *http.Request) error { return binder.BindStructToHTTPHeader(dst, "header", r.Header) }) DefaultValidateFunc = func(v interface{}, r *http.Request) error { return defaults.ValidateStruct(v) } BodyBinder Binder = WrapBinder(DefaultMuxBinder, DefaultValidateFunc) QueryBinder Binder = WrapBinder(DefaultQueryBinder, DefaultValidateFunc) HeaderBinder Binder = WrapBinder(DefaultHeaderBinder, DefaultValidateFunc) )
Predefine some binder to bind the body, query and header of the request.
func FormBinder ¶
FormBinder returns a binder to bind the data to the request body as Form, which supports the struct tag "form".
func JSONBinder ¶
func JSONBinder() Binder
JSONBinder returns a binder to bind the data to the request body as JSON.
func WrapBinder ¶ added in v0.18.0
WrapBinder wraps the binder and returns a new one that goes to handle the result after binding the request.
type MuxBinder ¶
type MuxBinder struct {
// contains filtered or unexported fields
}
MuxBinder is a multiplexer for kinds of Binders based on the request header "Content-Type".
func (*MuxBinder) Bind ¶
Bind implements the interface Binder, which looks up the registered binder by the request header "Content-Type" and calls it to bind the value dst to req.