Binder

binder

github.com/gofiber/fiber/v3/binder

import "github.com/gofiber/fiber/v3/binder"

Constants

Source: binder/form.go:13

const MIMEMultipartForm string = "multipart/form-data"

Variables

Binder errors

Source: binder/binder.go:19

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")
)

Source: binder/binder.go:79

var CBORBinderPool = sync.Pool{
	New: func() any {
		return &CBORBinding{}
	},
}

Source: binder/binder.go:43

var CookieBinderPool = sync.Pool{
	New: func() any {
		return &CookieBinding{}
	},
}

Source: binder/msgpack.go:9

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.

Source: binder/cbor.go:31

var ErrUnimplementedCBOR = errors.New("binder: must explicitly set up CBOR, please check docs: https://docs.gofiber.io/next/guide/advance-format#cbor")

Source: binder/binder.go:55

var FormBinderPool = sync.Pool{
	New: func() any {
		return &FormBinding{}
	},
}

Source: binder/binder.go:31

var HeaderBinderPool = sync.Pool{
	New: func() any {
		return &HeaderBinding{}
	},
}

Source: binder/binder.go:73

var JSONBinderPool = sync.Pool{
	New: func() any {
		return &JSONBinding{}
	},
}

Source: binder/binder.go:85

var MsgPackBinderPool = sync.Pool{
	New: func() any {
		return &MsgPackBinding{}
	},
}

Source: binder/binder.go:49

var QueryBinderPool = sync.Pool{
	New: func() any {
		return &QueryBinding{}
	},
}

Source: binder/binder.go:37

var RespHeaderBinderPool = sync.Pool{
	New: func() any {
		return &RespHeaderBinding{}
	},
}

Source: binder/binder.go:61

var URIBinderPool = sync.Pool{
	New: func() any {
		return &URIBinding{}
	},
}

Source: binder/binder.go:67

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

Source: binder/binder.go:93

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)

Source: binder/binder.go:103

PutToThePool returns the binder to the provided sync.Pool.

func SetParserDecoder(parserConfig ParserConfig)

Source: binder/mapping.go:97

SetParserDecoder allow globally change the option of form decoder, update decoderPool

func UnimplementedCborMarshal(_ any) ([]byte, error)

Source: binder/cbor.go:35

UnimplementedCborMarshal returns an error to signal that a CBOR marshaler must be configured before CBOR support can be used.

func UnimplementedCborUnmarshal(_ []byte, _ any) error

Source: binder/cbor.go:41

UnimplementedCborUnmarshal returns an error to signal that a CBOR unmarshaler must be configured before CBOR support can be used.

func UnimplementedMsgpackMarshal(_ any) ([]byte, error)

Source: binder/msgpack.go:33

UnimplementedMsgpackMarshal returns an error to signal that a MsgPack marshaler must be configured before MsgPack support can be used.

func UnimplementedMsgpackUnmarshal(_ []byte, _ any) error

Source: binder/msgpack.go:39

UnimplementedMsgpackUnmarshal returns an error to signal that a MsgPack unmarshaler must be configured before MsgPack support can be used.

Types

type CBORBinding

Source: binder/cbor.go:10

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

Source: binder/cbor.go:20

Bind parses the request body as CBOR and returns the result.

func (*CBORBinding) Name() string

Source: binder/cbor.go:15

Name returns the binding name.

func (b *CBORBinding) Reset()

Source: binder/cbor.go:25

Reset resets the CBORBinding binder.

type CookieBinding

Source: binder/cookie.go:9

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

Source: binder/cookie.go:19

Bind parses the request cookie and returns the result.

func (*CookieBinding) Name() string

Source: binder/cookie.go:14

Name returns the binding name.

func (b *CookieBinding) Reset()

Source: binder/cookie.go:59

Reset resets the CookieBinding binder.

type FormBinding

Source: binder/form.go:36

FormBinding is the form binder for form request body.

type FormBinding struct {
	EnableSplitting bool
	MaxBodySize     int
}
Fields
  • EnableSplitting bool
  • MaxBodySize int

func (b *FormBinding) Bind(req *fasthttp.Request, out any) error

Source: binder/form.go:47

Bind parses the request body and returns the result.

func (*FormBinding) Name() string

Source: binder/form.go:42

Name returns the binding name.

func (b *FormBinding) Reset()

Source: binder/form.go:132

Reset resets the FormBinding binder.

type HeaderBinding

Source: binder/header.go:10

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

Source: binder/header.go:20

Bind parses the request header and returns the result.

func (*HeaderBinding) Name() string

Source: binder/header.go:15

Name returns the binding name.

func (b *HeaderBinding) Reset()

Source: binder/header.go:36

Reset resets the HeaderBinding binder.

type JSONBinding

Source: binder/json.go:8

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

Source: binder/json.go:18

Bind parses the request body as JSON and returns the result.

func (*JSONBinding) Name() string

Source: binder/json.go:13

Name returns the binding name.

func (b *JSONBinding) Reset()

Source: binder/json.go:23

Reset resets the JSONBinding binder.

type MsgPackBinding

Source: binder/msgpack.go:12

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

Source: binder/msgpack.go:22

Bind parses the request body as MsgPack and returns the result.

func (*MsgPackBinding) Name() string

Source: binder/msgpack.go:17

Name returns the binding name.

func (b *MsgPackBinding) Reset()

Source: binder/msgpack.go:27

Reset resets the MsgPackBinding binder.

type ParserConfig

Source: binder/mapping.go:24

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 string

    SetAliasTag is ignored: every binder decodes with the tag of its own source.

  • ParserType []ParserType
  • IgnoreUnknownKeys bool
  • ZeroEmpty bool

type ParserType

Source: binder/mapping.go:34

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 any
  • Converter func(string) reflect.Value
  • ConverterE func(string) (reflect.Value, error)

type QueryBinding

Source: binder/query.go:9

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

Source: binder/query.go:19

Bind parses the request query and returns the result.

func (*QueryBinding) Name() string

Source: binder/query.go:14

Name returns the binding name.

func (b *QueryBinding) Reset()

Source: binder/query.go:36

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

Source: binder/uri.go:4

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

Source: binder/uri.go:12

Bind parses the URI parameters and returns the result.

func (*URIBinding) Name() string

Source: binder/uri.go:7

Name returns the binding name.

func (*URIBinding) Reset()

Source: binder/uri.go:24

Reset resets URIBinding binder.

type XMLBinding

Source: binder/xml.go:10

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

Source: binder/xml.go:20

Bind parses the request body as XML and returns the result.

func (*XMLBinding) Name() string

Source: binder/xml.go:15

Name returns the binding name.

func (b *XMLBinding) Reset()

Source: binder/xml.go:29

Reset resets the XMLBinding binder.