validate

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Validate = validator.New()
)

校验器

Functions

func BindValidate

func BindValidate(r *http.Request, obj interface{}, vr *ValidateResult)

bindValidate 解析请求并将数据注入到指定对象,返回解析结果

func CheckValidateData

func CheckValidateData(r *http.Request, validateData interface{}, vr *ValidateResult) interface{}

CheckValidateData 校验及获取一个用于绑定的 model 对象

func DecodeTo

func DecodeTo(r *http.Request, obj interface{}, vr *ValidateResult)

DecodeTo

func Parse

func Parse(r *http.Request, vr *ValidateResult)

Parse

func SetStrictJSONBodyCheck

func SetStrictJSONBodyCheck(b bool)

SetStrictJSONBodyCheck 设置 strictJSONBodyCheck 若 strictJSONBodyCheck 值为 true 且请求为 json 请求,则读取到空的数据将抛出异常

func StrictJSONBodyCheck

func StrictJSONBodyCheck() bool

StrictJSONBodyCheck 获取 strictJSONBodyCheck 若 strictJSONBodyCheck 值为 true 且请求为 json 请求,则读取到空的数据将抛出异常

func ValidatorStandErrMsg

func ValidatorStandErrMsg(err error) string

ValidatorStandErrMsg 构建请求错误提示信息

Types

type RequestValidate

type RequestValidate interface {
	Validate(r *http.Request) (ok bool, errMsg string)
}

RequestValidate 实现该接口的不同VO(请求结构体)可以自校验

type ValidateFunc

type ValidateFunc func(r *http.Request) (interface{}, error)

ValidateFunc 自定义当前请求需要用到的 VO 对象,用于 返回的 VO 不应该为 nil,若无法返回正确的 VO 应该在返回的 error 中进行说明

type ValidateResult

type ValidateResult struct {
	Err         error
	MediaType   string
	BodyBytes   []byte
	BodyValues  url.Values
	QueryValues url.Values
}

ValidateResult 请求校验结果

Jump to

Keyboard shortcuts

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