binder

package
v3.14.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindURLValues

func BindURLValues(ptr interface{}, data url.Values, tag string) error

BindURLValues parses the data and assign to the pointer ptr to a struct.

Notice: tag is the name of the struct tag. such as "form", "query", etc. If the tag value is equal to "-", ignore this field.

Types

type BindUnmarshaler

type BindUnmarshaler interface {
	// Unmarshal decodes the argument param and assigns to itself.
	UnmarshalBind(param string) error
}

BindUnmarshaler is the interface used to wrap the UnmarshalParam method.

type Binder

type Binder interface {
	// Bind parses the data from http.Request to v.
	//
	// Notice: v must be a non-nil pointer.
	Bind(req *http.Request, v interface{}) error
}

Binder is the interface to bind the value to v from ctx.

func BinderFunc

func BinderFunc(f func(*http.Request, interface{}) error) Binder

BinderFunc converts a function to Binder.

func FormBinder

func FormBinder(maxMemory int64, tag ...string) Binder

FormBinder returns a Form binder to bind the Form request.

Notice: The bound value must be a pointer to a struct. You can modify the name of the field by the tag, which is "form" by default.

func JSONBinder

func JSONBinder() Binder

JSONBinder returns a JSON binder to bind the JSON request.

func QueryBinder

func QueryBinder(tag ...string) Binder

QueryBinder returns a query binder to bind the query parameters..

Notice: The bound value must be a pointer to a struct. You can modify the name of the field by the tag, which is "query" by default.

func XMLBinder

func XMLBinder() Binder

XMLBinder returns a XML binder to bind the XML request.

type MuxBinder

type MuxBinder struct {
	// contains filtered or unexported fields
}

MuxBinder is a multiplexer for kinds of Binders based on the Content-Type.

func NewMuxBinder

func NewMuxBinder() *MuxBinder

NewMuxBinder returns a new MuxBinder.

func (*MuxBinder) Add

func (mb *MuxBinder) Add(contentType string, binder Binder)

Add adds a binder to bind the content for the header Content-Type.

func (*MuxBinder) Bind

func (mb *MuxBinder) Bind(req *http.Request, v interface{}) error

Bind implements the interface Binder, which will call the registered binder to bind the request to v by the request header Content-Type.

func (*MuxBinder) Del

func (mb *MuxBinder) Del(contentType string)

Del removes the corresponding binder by the header Content-Type.

func (*MuxBinder) Get

func (mb *MuxBinder) Get(contentType string) Binder

Get returns the corresponding binder by the header Content-Type.

Return nil if not found.

Jump to

Keyboard shortcuts

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