binder
import "github.com/gofiber/fiber/v3/binder"
Constants
const MIMEMultipartForm string = "multipart/form-data"Variables
Binder errors
var (
ErrSuitableContentNotFound = errors.New("binder: suitable content not found to parse body")
ErrMapNotConvertible = errors.New("binder: map is not convertible to map[string]string or map[string][]string")
ErrMapNilDestination = errors.New("binder: map destination is nil and cannot be initialized")
ErrInvalidDestinationValue = errors.New("binder: invalid destination value")
ErrUnmatchedBrackets = errors.New("unmatched brackets")
ErrKeyTooDeep = errors.New("binder: key is nested too deeply")
ErrTooManyElements = errors.New("binder: keys index too many nested slice elements")
ErrFormContentEncoding = errors.New("binder: the form parser does not undo the form's Content-Encoding as Body does")
)var CBORBinderPool = sync.Pool{
New: func() any {
return &CBORBinding{}
},
}var CookieBinderPool = sync.Pool{
New: func() any {
return &CookieBinding{}
},
}var ErrMsgPackNotConfigured = errors.New("binder: msgpack is not configured, please check docs: https://docs.gofiber.io/next/guide/advance-format#msgpack")ErrUnimplementedCBOR signals that CBOR support must be explicitly configured before it can be used.
var ErrUnimplementedCBOR = errors.New("binder: must explicitly set up CBOR, please check docs: https://docs.gofiber.io/next/guide/advance-format#cbor")var FormBinderPool = sync.Pool{
New: func() any {
return &FormBinding{}
},
}var HeaderBinderPool = sync.Pool{
New: func() any {
return &HeaderBinding{}
},
}var JSONBinderPool = sync.Pool{
New: func() any {
return &JSONBinding{}
},
}var MsgPackBinderPool = sync.Pool{
New: func() any {
return &MsgPackBinding{}
},
}var QueryBinderPool = sync.Pool{
New: func() any {
return &QueryBinding{}
},
}var RespHeaderBinderPool = sync.Pool{
New: func() any {
return &RespHeaderBinding{}
},
}var URIBinderPool = sync.Pool{
New: func() any {
return &URIBinding{}
},
}var XMLBinderPool = sync.Pool{
New: func() any {
return &XMLBinding{}
},
}Functions
func FilterFlags(content string) string
Source: binder/mapping.go:1005
FilterFlags returns the media type value by trimming any parameters from a Content-Type header. The media type ends at the ';' or the space or tab before it, as fasthttp's form readers end it.
func GetFromThePool[T any](pool *sync.Pool) T
GetFromThePool retrieves a binder from the provided sync.Pool and panics if the stored value cannot be cast to the requested type.
func PutToThePool[T any](pool *sync.Pool, binder T)
PutToThePool returns the binder to the provided sync.Pool.
func SetParserDecoder(parserConfig ParserConfig)
SetParserDecoder allow globally change the option of form decoder, update decoderPool
func UnimplementedCborMarshal(_ any) ([]byte, error)
UnimplementedCborMarshal returns an error to signal that a CBOR marshaler must be configured before CBOR support can be used.
func UnimplementedCborUnmarshal(_ []byte, _ any) error
UnimplementedCborUnmarshal returns an error to signal that a CBOR unmarshaler must be configured before CBOR support can be used.
func UnimplementedMsgpackMarshal(_ any) ([]byte, error)
UnimplementedMsgpackMarshal returns an error to signal that a MsgPack marshaler must be configured before MsgPack support can be used.
func UnimplementedMsgpackUnmarshal(_ []byte, _ any) error
UnimplementedMsgpackUnmarshal returns an error to signal that a MsgPack unmarshaler must be configured before MsgPack support can be used.
Types
type CBORBinding
CBORBinding is the CBOR binder for CBOR request body.
type CBORBinding struct {
CBORDecoder utils.CBORUnmarshal
}Fields
CBORDecoder utils.CBORUnmarshal
func (b *CBORBinding) Bind(body []byte, out any) error
Bind parses the request body as CBOR and returns the result.
func (*CBORBinding) Name() string
Name returns the binding name.
func (b *CBORBinding) Reset()
Reset resets the CBORBinding binder.
type CookieBinding
CookieBinding is the cookie binder for cookie request body.
type CookieBinding struct {
EnableSplitting bool
}Fields
EnableSplitting bool
func (b *CookieBinding) Bind(req *fasthttp.Request, out any) error
Bind parses the request cookie and returns the result.
func (*CookieBinding) Name() string
Name returns the binding name.
func (b *CookieBinding) Reset()
Reset resets the CookieBinding binder.
type FormBinding
FormBinding is the form binder for form request body.
type FormBinding struct {
EnableSplitting bool
MaxBodySize int
}Fields
EnableSplitting boolMaxBodySize int
func (b *FormBinding) Bind(req *fasthttp.Request, out any) error
Bind parses the request body and returns the result.
func (*FormBinding) Name() string
Name returns the binding name.
func (b *FormBinding) Reset()
Reset resets the FormBinding binder.
type HeaderBinding
HeaderBinding is the binder implementation used to populate values from HTTP headers.
type HeaderBinding struct {
EnableSplitting bool
}Fields
EnableSplitting bool
func (b *HeaderBinding) Bind(req *fasthttp.Request, out any) error
Bind parses the request header and returns the result.
func (*HeaderBinding) Name() string
Name returns the binding name.
func (b *HeaderBinding) Reset()
Reset resets the HeaderBinding binder.
type JSONBinding
JSONBinding is the JSON binder for JSON request body.
type JSONBinding struct {
JSONDecoder utils.JSONUnmarshal
}Fields
JSONDecoder utils.JSONUnmarshal
func (b *JSONBinding) Bind(body []byte, out any) error
Bind parses the request body as JSON and returns the result.
func (*JSONBinding) Name() string
Name returns the binding name.
func (b *JSONBinding) Reset()
Reset resets the JSONBinding binder.
type MsgPackBinding
MsgPackBinding is the MsgPack binder for MsgPack request body.
type MsgPackBinding struct {
MsgPackDecoder utils.MsgPackUnmarshal
}Fields
MsgPackDecoder utils.MsgPackUnmarshal
func (b *MsgPackBinding) Bind(body []byte, out any) error
Bind parses the request body as MsgPack and returns the result.
func (*MsgPackBinding) Name() string
Name returns the binding name.
func (b *MsgPackBinding) Reset()
Reset resets the MsgPackBinding binder.
type ParserConfig
ParserConfig form decoder config for SetParserDecoder
type ParserConfig struct {
// SetAliasTag is ignored: every binder decodes with the tag of its own source.
SetAliasTag string
ParserType []ParserType
IgnoreUnknownKeys bool
ZeroEmpty bool
}Fields
SetAliasTag stringSetAliasTag is ignored: every binder decodes with the tag of its own source.
ParserType []ParserTypeIgnoreUnknownKeys boolZeroEmpty bool
type ParserType
ParserType configures a converter for the type of CustomType. ConverterE takes precedence over Converter when both are set.
type ParserType struct {
CustomType any
Converter func(string) reflect.Value
ConverterE func(string) (reflect.Value, error)
}Fields
CustomType anyConverter func(string) reflect.ValueConverterE func(string) (reflect.Value, error)
type QueryBinding
QueryBinding is the query binder for query request body.
type QueryBinding struct {
EnableSplitting bool
}Fields
EnableSplitting bool
func (b *QueryBinding) Bind(reqCtx *fasthttp.Request, out any) error
Bind parses the request query and returns the result.
func (*QueryBinding) Name() string
Name returns the binding name.
func (b *QueryBinding) Reset()
Reset resets the QueryBinding binder.
type RespHeaderBinding
Source: binder/resp_header.go:9
RespHeaderBinding is the respHeader binder for response header.
type RespHeaderBinding struct {
EnableSplitting bool
}Fields
EnableSplitting bool
func (b *RespHeaderBinding) Bind(resp *fasthttp.Response, out any) error
Source: binder/resp_header.go:19
Bind parses the response header and returns the result.
func (*RespHeaderBinding) Name() string
Source: binder/resp_header.go:14
Name returns the binding name.
func (b *RespHeaderBinding) Reset()
Source: binder/resp_header.go:35
Reset resets the RespHeaderBinding binder.
type URIBinding
URIBinding is the binder implementation for populating values from route parameters.
type URIBinding struct{}func (b *URIBinding) Bind(params []string, paramsFunc func(key string, defaultValue ...string) string, out any) error
Bind parses the URI parameters and returns the result.
func (*URIBinding) Name() string
Name returns the binding name.
func (*URIBinding) Reset()
Reset resets URIBinding binder.
type XMLBinding
XMLBinding is the XML binder for XML request body.
type XMLBinding struct {
XMLDecoder utils.XMLUnmarshal
}Fields
XMLDecoder utils.XMLUnmarshal
func (b *XMLBinding) Bind(body []byte, out any) error
Bind parses the request body as XML and returns the result.
func (*XMLBinding) Name() string
Name returns the binding name.
func (b *XMLBinding) Reset()
Reset resets the XMLBinding binder.