binding

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2020 License: MIT Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	MIMEJSON              = "application/json"
	MIMEHTML              = "text/html"
	MIMEXML               = "application/xml"
	MIMEXML2              = "text/xml"
	MIMEPlain             = "text/plain"
	MIMEPOSTForm          = "application/x-www-form-urlencoded"
	MIMEMultipartPOSTForm = "multipart/form-data"
)

Variables

View Source
var (
	Form          = formBinding{}
	FormPost      = formPostBinding{}
	FormMultipart = formMultipartBinding{}
	Header        = headerBinding{}
	JSON          = jsonBinding{}
	Query         = queryBinding{}
	Uri           = uriBinding{}
	XML           = xmlBinding{}
)

实现Binding接口,并可用于将请求中的数据绑定到struct实例

View Source
var EnableDecoderDisallowUnknownFields = false

EnableDecoderDisallowUnknownFields 用于调用JSON解码器实例上的DisallowUnknownFields方法. 当目标为结构且输入包含与目标中任何未忽略的导出字段不匹配的对象键时,使解码器返回错误.

View Source
var EnableDecoderUseNumber = false

EnableDecoderUseNumber 用于调用JSON解码器实例上的UseNumber方法. UseNumber 使解码器将一个数字解组到接口中,作为数字而不是float64.

Functions

This section is empty.

Types

type Binding

type Binding interface {
	Name() string
	Bind(*http.Request, interface{}) error
}

Binding 绑定请求中的数据所需实现的接口(如JSON请求体、查询参数或表单POST)

func Default

func Default(method, contentType string) Binding

Default 根据HTTP方法和内容类型返回适当的添加BindUri方法到Binding实例.

type BindingBody

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

BindingBody 添加BindBody方法到Binding. BindBody与Bind类似,但它从提供的bytes读取,而不是req.Body.

type BindingUri

type BindingUri interface {
	Name() string
	BindUri(map[string][]string, interface{}) error
}

BindingUri 添加BindUri方法到Binding. BindUri与Bind类似,但它读取Params

type StructValidator

type StructValidator interface {
	ValidateStruct(interface{}) error // 可接收任何类型,即使配置不正确,也不引发异常.
	Engine() interface{}              // 提供支持的基础验证器
}

StructValidator 是需要实现的最小接口,以便用作验证中枢,以确保请求的正确性.

var Validator StructValidator = &defaultValidator{}

Validator 实现StructValidator接口的默认验证器.

Jump to

Keyboard shortcuts

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