binding

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

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)

func RegisterScopeTag

func RegisterScopeTag(scope BindScope, tag string)

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