binding

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 16, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	JSON          = jsonBinding{}
	XML           = xmlBinding{}
	Query         = queryBinding{}
	FormPost      = formPostBinding{}
	FormMultipart = formMultipartBinding{}
	ProtoBuf      = protobufBinding{}
	MsgPack       = msgpackBinding{}
	YAML          = yamlBinding{}
	Header        = headerBinding{}
)

Functions

func Bind

func Bind(c *fasthttp.RequestCtx, obj interface{}) error

func BindJSON

func BindJSON(r *fasthttp.RequestCtx, obj interface{}) error

BindJSON is a shortcut for c.MustBindWith(obj, binding.JSON).

func BindQuery

func BindQuery(r *fasthttp.RequestCtx, obj interface{}) error

BindQuery is a shortcut for c.MustBindWith(obj, binding.Query).

func BindXML

func BindXML(r *fasthttp.RequestCtx, obj interface{}) error

BindXML is a shortcut for c.MustBindWith(obj, binding.BindXML).

func BindYAML

func BindYAML(r *fasthttp.RequestCtx, obj interface{}) error

BindYAML is a shortcut for c.MustBindWith(obj, binding.YAML).

func MustBindWith

func MustBindWith(r *fasthttp.RequestCtx, obj interface{}, b Binding) error

MustBindWith binds the passed struct pointer using the specified binding engine. It will abort the request with HTTP 400 if any error occurs. See the binding package.

func NewReq

func NewReq[REQ any](c *fasthttp.RequestCtx) (*REQ, error)

func ShouldBind

func ShouldBind(r *fasthttp.RequestCtx, obj interface{}) error

ShouldBind checks the Content-Type to select a binding engine automatically, Depending the "Content-Type" header different bindings are used:

"application/json" --> JSON binding
"application/xml"  --> XML binding

otherwise --> returns an error It parses the request's body as JSON if Content-Type == "application/json" using JSON or XML as a JSON input. It decodes the json payload into the struct specified as a pointer. Like c.GinBind() but this method does not set the response status code to 400 and abort if the json is not valid.

func ShouldBindJSON

func ShouldBindJSON(r *fasthttp.RequestCtx, obj interface{}) error

ShouldBindJSON is a shortcut for c.ShouldBindWith(obj, binding.JSON).

func ShouldBindQuery

func ShouldBindQuery(r *fasthttp.RequestCtx, obj interface{}) error

ShouldBindQuery is a shortcut for c.ShouldBindWith(obj, binding.Query).

func ShouldBindWith

func ShouldBindWith(r *fasthttp.RequestCtx, obj interface{}, b Binding) error

ShouldBindWith binds the passed struct pointer using the specified binding engine. See the binding package.

func ShouldBindXML

func ShouldBindXML(r *fasthttp.RequestCtx, obj interface{}) error

ShouldBindXML is a shortcut for c.ShouldBindWith(obj, binding.XML).

func ShouldBindYAML

func ShouldBindYAML(r *fasthttp.RequestCtx, obj interface{}) error

ShouldBindYAML is a shortcut for c.ShouldBindWith(obj, binding.YAML).

Types

type ArgsSource

type ArgsSource fasthttp.Args

func (*ArgsSource) Peek

func (form *ArgsSource) Peek(key string) ([]string, bool)

func (*ArgsSource) TrySet

func (form *ArgsSource) TrySet(value reflect.Value, field reflect.StructField, tagValue string, opt binding.SetOptions) (isSet bool, err error)

TrySet tries to set a value by request's form source (like map[string][]string)

type Binding

type Binding interface {
	Name() string
	Bind(*fasthttp.RequestCtx, interface{}) error
}

func Body

func Body(contentType []byte) Binding

func Default

func Default(method, contentType []byte) Binding

type BindingBody

type BindingBody interface {
	Binding
	BindBody([]byte, interface{}) error
}

type CtxSource

type CtxSource fasthttp.RequestCtx

func (*CtxSource) Peek

func (form *CtxSource) Peek(key string) ([]string, bool)

func (*CtxSource) TrySet

func (form *CtxSource) TrySet(value reflect.Value, field reflect.StructField, tagValue string, opt binding.SetOptions) (isSet bool, err error)

TrySet tries to set a value by request's form source (like map[string][]string)

type HeaderSource

type HeaderSource fasthttp.RequestHeader

func (*HeaderSource) Peek

func (form *HeaderSource) Peek(key string) ([]string, bool)

func (*HeaderSource) TrySet

func (form *HeaderSource) TrySet(value reflect.Value, field reflect.StructField, tagValue string, opt binding.SetOptions) (isSet bool, err error)

TrySet tries to set a value by request's form source (like map[string][]string)

type MultipartRequest

type MultipartRequest fasthttp.Request

func (*MultipartRequest) TrySet

func (r *MultipartRequest) TrySet(value reflect.Value, field reflect.StructField, key string, opt binding.SetOptions) (isSet bool, err error)

TrySet tries to set a value by the multipart request with the binding a form file

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL