Documentation ¶
Index ¶
- func Email(field interface{}) error
- func Field(field interface{}, tag string) error
- func File(field interface{}) error
- func HttpUrl(field interface{}) error
- func IP(field interface{}) error
- func IPv4(field interface{}) error
- func Json(field interface{}) error
- func New(tagNameArgs ...string) *validator.Validate
- func Port(field interface{}) error
- func Required(field interface{}) error
- func Struct(s interface{}) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func File ¶
func File(field interface{}) error
File 字符串值是否包含有效的文件路径,以及该文件是否存在于计算机上.
PS: 传参对应的应当是"文件",是"目录"的话会返回error. e.g. fmt.Println(validateKit.File("")) // Key: '' Error:Field validation for '' failed on the 'file' tag // 目录存在 fmt.Println(validateKit.File("_chimera-lib")) // Key: '' Error:Field validation for '' failed on the 'file' tag fmt.Println(validateKit.File("/Users/richelieu/GolandProjects/chimera/_chimera-lib")) // Key: '' Error:Field validation for '' failed on the 'file' tag // 文件存在 fmt.Println(validateKit.File("_chimera-lib/config.yaml")) // <nil> fmt.Println(validateKit.File("/Users/richelieu/GolandProjects/chimera/_chimera-lib/config.yaml")) // <nil> // 文件不存在 fmt.Println(validateKit.File("/Users/richelieu/GolandProjects/chimera/_chimera-lib/config111.yaml")) // Key: '' Error:Field validation for '' failed on the 'file' tag // 无效的文件路径 fmt.Println(validateKit.File("chimera-lib\\config.yaml")) // Key: '' Error:Field validation for '' failed on the 'file' tag
func HttpUrl ¶
func HttpUrl(field interface{}) error
HttpUrl
PS: 要以 "http://" 或 "https://" 开头. e.g. fmt.Println(validateKit.HttpUrl("")) // Key: '' Error:Field validation for '' failed on the 'http_url' tag fmt.Println(validateKit.HttpUrl("https://github.com/go-playground/validator")) // <nil> fmt.Println(validateKit.HttpUrl("http://github.com/go-playground/validator")) // <nil> fmt.Println(validateKit.HttpUrl("ftp://github.com/go-playground/validator")) // Key: '' Error:Field validation for '' failed on the 'http_url' tag
func IP ¶
func IP(field interface{}) error
IP
e.g. fmt.Println(validateKit.IP("")) // Key: '' Error:Field validation for '' failed on the 'ip' tag fmt.Println(validateKit.IP("127.0.0.1")) // <nil> fmt.Println(validateKit.IP("127.001")) // Key: '' Error:Field validation for '' failed on the 'ip' tag
func Json ¶
func Json(field interface{}) error
Json 字符串值是否为有效的JSON.
e.g. fmt.Println(validateKit.Json("")) // Key: '' Error:Field validation for '' failed on the 'json' tag fmt.Println(validateKit.Json("[]")) // <nil> fmt.Println(validateKit.Json("{}")) // <nil> fmt.Println(validateKit.Json("[}")) // Key: '' Error:Field validation for '' failed on the 'json' tag
func New ¶
func New(tagNameArgs ...string) *validator.Validate
New
@param tagNameArgs 不传参的话,将采用默认的tag name("validate")
func Required ¶
func Required(field interface{}) error
Required 必填,非零值(zero value)
e.g. fmt.Println(validateKit.Required(nil)) // Key: '' Error:Field validation for '' failed on the 'required' tag fmt.Println(validateKit.Required("")) // Key: '' Error:Field validation for '' failed on the 'required' tag fmt.Println(validateKit.Required("aaa")) // <nil> fmt.Println(validateKit.Required(0)) // Key: '' Error:Field validation for '' failed on the 'required' tag fmt.Println(validateKit.Required(1)) // <nil> fmt.Println(validateKit.Required(false)) // Key: '' Error:Field validation for '' failed on the 'required' tag fmt.Println(validateKit.Required(true)) // <nil>
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.