validator

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2021 License: MIT Imports: 4 Imported by: 0

README

validator

介绍

golang参数验证包

欢迎各位大佬指导

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetDefaultErrorCode

func SetDefaultErrorCode(code int)

SetDefaultErrorCode 设置默认验证错误错误码

func SetFunction

func SetFunction(name string, function Function)

SetFunction 设置验证函数

func SetTag

func SetTag(tag string)

SetTag 设置验证标签名

Types

type Error

type Error struct {
	// Code 错误码
	Code int
	// Message 错误信息
	Message string
}

Error 验证错误信息,实现error接口

func Validate

func Validate(value interface{}) (error *Error)

Validate 验证参数

func (Error) Error

func (e Error) Error() (errorString string)

Error 实现error接口

type Function

type Function func(value interface{}, code int, condition string) (error *Error)

Function 验证函数类型

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Validator 验证器

func NewValidator

func NewValidator() (validator *Validator)

NewValidator 新建验证器

func (*Validator) SetFunction

func (v *Validator) SetFunction(name string, function Function)

SetFunction 设置验证函数

func (*Validator) SetTag

func (v *Validator) SetTag(tag string)

SetTag 设置验证标签名

func (*Validator) Validate

func (v *Validator) Validate(value interface{}) (error *Error)

Validate 验证参数 todo 结构体嵌套递归判断、关联字段验证

Jump to

Keyboard shortcuts

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