This is a created article in which the information may have evolved or changed.
Golang_validator
Freely customizable Golang parameter verifier
About the component:
This component is highly customizable and can be used as an example:
type testValidator struct { ItemNum int `valid:"PosNO" name:"items" ` // 验证是否是正数 IsCount int `valid:"PosNO"`}
Valid for validation, followed by the name of the function to be validated: This can be written if you want to validate for integers and strings:
`valid:"PosNO,Str"
Name indicates the name of the current field
To extend, verify that the function is in the following format:
func (this *Validator) CheckPosNO(data int, tag reflect.StructTag) error { if data <= 0 { return errors.New(tag.Get("name") + ":不能为负数!") } return nil }
The check represents the prefix of the function and is written on the label when called: Posno can
With regard to this component, many of the web frameworks currently Golang are available, but why should the author write it himself for the following reasons:
While many frameworks are available, there is little support for customization. So I wrote one based on the needs of the project.
Download Address:
Https://github.com/yingtianxun/golang_validator/blob/master/README.md