binding

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Overview

Package binding ...

Index

Constants

View Source
const (
	MIMEApplicationJSON = "application/json"
	MIMEApplicationXML  = "application/xml"
	MIMETextXML         = "text/xml"
	MIMEApplicationForm = "application/x-www-form-urlencoded"
	MIMEMultipartForm   = "multipart/form-data"
)

Variables

View Source
var ErrBinding = errors.New("binding failed")
View Source
var ErrValidate = errors.New("validate failed")

Functions

func Bind

func Bind(i interface{}, r Request) error

Bind checks the Method and Content-Type to select a binding engine automatically, Depending on the "Content-Type" header different bindings are used, for example:

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

func BindForm

func BindForm(i interface{}, r Request) error

func BindJSON

func BindJSON(i interface{}, r Request) error

func BindMultipartForm

func BindMultipartForm(i interface{}, r Request) error

func BindXML

func BindXML(i interface{}, r Request) error

func RegisterBodyBinder

func RegisterBodyBinder(mime string, binder BodyBinder)

RegisterBodyBinder register body binder.

func RegisterConverter

func RegisterConverter(typ reflect.Type, converter FieldConverter)

RegisterConverter register custom field type converter.

func RegisterValidator

func RegisterValidator(validator func(i interface{}) error)

RegisterValidator register custom validator.

Types

type BindScope

type BindScope int
const (
	BindScopeURI BindScope = iota
	BindScopeQuery
	BindScopeHeader
	BindScopeCookie
	BindScopeBody
)

type BodyBinder

type BodyBinder func(i interface{}, r Request) error

type FieldConverter

type FieldConverter func(v reflect.Value, val string) error

type Request

type Request interface {
	ContentType() string
	Header(key string) (string, bool)
	Cookie(name string) (string, bool)
	PathParam(name string) (string, bool)
	QueryParam(name string) (string, bool)
	FormParams() (url.Values, error)
	MultipartParams(maxMemory int64) (*multipart.Form, error)
	RequestBody() io.Reader
}

Jump to

Keyboard shortcuts

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