binding

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: MIT, Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultMemory    int64 = 32 << 20
	BodyUnmarshaller       = bodyUnmarshaller
	CommonTag              = "json"
	Validate               = validator.ValidateStruct
)

Functions

func Bind

func Bind(r *http.Request, obj any) error

func CommonBind

func CommonBind(s Source, obj any) error

unhandle multipart form data currently

func FormUnmarshal added in v1.7.2

func FormUnmarshal(data []byte, obj any) error

func SetByMultipartFormFile

func SetByMultipartFormFile(value reflect.Value, field *reflect.StructField, files []*multipart.FileHeader) (isSet bool, err error)

Types

type Field

type Field struct {
	Name  string
	Tags  []Tag
	Index int
	Field *reflect.StructField
}

type HeaderSource

type HeaderSource map[string][]string

func (HeaderSource) HasValue

func (hs HeaderSource) HasValue(key string) bool

func (HeaderSource) Peek

func (hs HeaderSource) Peek(key string) ([]string, bool)

func (HeaderSource) TrySet

func (hs HeaderSource) TrySet(value reflect.Value, field *reflect.StructField, key string, opt *kvstruct.Options) (isSet bool, err error)

type MultipartSource

type MultipartSource multipart.Form

func (*MultipartSource) HasValue

func (ms *MultipartSource) HasValue(key string) bool

func (*MultipartSource) TrySet

func (ms *MultipartSource) TrySet(value reflect.Value, field *reflect.StructField, key string, opt *kvstruct.Options) (isSet bool, err error)

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

type RequestSource

type RequestSource struct {
	*http.Request
}

func (RequestSource) BodyBind

func (s RequestSource) BodyBind(obj any) error

func (RequestSource) Header

func (s RequestSource) Header() kvstruct.Setter

func (RequestSource) MultipartForm added in v1.7.2

func (s RequestSource) MultipartForm() kvstruct.Setter

func (RequestSource) Query

func (s RequestSource) Query() kvstruct.Setter

func (RequestSource) Uri

func (s RequestSource) Uri() kvstruct.Setter

type Source

type Source interface {
	Uri() kvstruct.Setter
	Query() kvstruct.Setter
	Header() kvstruct.Setter
	MultipartForm() kvstruct.Setter
	BodyBind(obj any) error
}

type Tag

type Tag struct {
	Key     string
	Value   string
	Options *kvstruct.Options
}

type UriSource

type UriSource http.Request

func (*UriSource) HasValue

func (req *UriSource) HasValue(key string) bool

func (*UriSource) Peek

func (req *UriSource) Peek(key string) ([]string, bool)

func (*UriSource) TrySet

func (req *UriSource) TrySet(value reflect.Value, field *reflect.StructField, key string, opt *kvstruct.Options) (isSet bool, err error)

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

Jump to

Keyboard shortcuts

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