-
Notifications
You must be signed in to change notification settings - Fork 0
/
validator.go
40 lines (33 loc) · 1.01 KB
/
validator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package xiren
import (
`github.com/go-playground/validator/v10`
`github.com/goexl/baozheng`
)
func initValidator(validate *validator.Validate) (err error) {
if err = validate.RegisterValidation(`mobile`, func(fl validator.FieldLevel) bool {
return baozheng.Mobile(fl.Field().String())
}); nil != err {
return
}
if err = validate.RegisterValidation(`password`, func(fl validator.FieldLevel) bool {
return baozheng.Password(fl.Field().String())
}); nil != err {
return
}
if err = validate.RegisterValidation(`filename`, func(fl validator.FieldLevel) bool {
return baozheng.Filename(fl.Field().String())
}); nil != err {
return
}
if err = validate.RegisterValidation(`start_with_alpha`, func(fl validator.FieldLevel) bool {
return baozheng.StartWithAlpha(fl.Field().String())
}); nil != err {
return
}
if err = validate.RegisterValidation(`prefix_or_suffix_space`, func(fl validator.FieldLevel) bool {
return baozheng.PrefixOrSuffixSpace(fl.Field().String())
}); nil != err {
return
}
return
}