valid

package
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

README

参数校验库

Documentation

Index

Constants

View Source
const (
	Int validType = iota
	String
	ArrayInt    //仅支持在json的内层使用
	ArrayString //仅支持在json的内层使用
)

批量检测参数

Variables

This section is empty.

Functions

This section is empty.

Types

type Regulation

type Regulation struct {
	Def       any       //默认值
	Name      string    //参数名称
	Desc      string    //参数描述
	Reg       string    //正则规则校验
	Min       int64     //最小值或最小长度
	Max       int64     //最大值或最大长度
	CheckType validType //校验类型
	Required  bool      //是否必填
}

Regulation 校验规则

type Valid

type Valid struct {
	MapData map[string]string //解析后的键值对
}

func NewValid

func NewValid(urlValues url.Values, jsonStr []byte) (*Valid, error)

NewValid 创建校验对象 url.Values url参数 或 post 键值对 参数只解析[0] 【数组不做处理】 jsonStr json字符串 当key相同时 json权重高于url.Values数据

func (*Valid) GetInt64

func (v *Valid) GetInt64(reg *Regulation) (bool, int64, error)

func (*Valid) GetIntArray

func (v *Valid) GetIntArray(reg *Regulation) (bool, []int64, error)

func (*Valid) GetString

func (v *Valid) GetString(reg *Regulation) (bool, string, error)

func (*Valid) GetStringArray

func (v *Valid) GetStringArray(reg *Regulation) (bool, []string, error)

func (*Valid) RegData

func (v *Valid) RegData(regs []*Regulation) (map[string]any, error)

RegData 根据规则校验参数 碰到错误立即返回

Jump to

Keyboard shortcuts

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