add validator model
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"lone-services/pkg/utils"
|
||||
"reflect"
|
||||
"regexp"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
@@ -17,9 +18,14 @@ type IValidator interface {
|
||||
}
|
||||
|
||||
var v *validator.Validate
|
||||
var mobileReg = regexp.MustCompile(`^1[3-9]\d{9}$`)
|
||||
|
||||
func init() {
|
||||
v = validator.New()
|
||||
|
||||
_ = v.RegisterValidation("mobile", func(fl validator.FieldLevel) bool {
|
||||
return mobileReg.MatchString(fl.Field().String())
|
||||
})
|
||||
}
|
||||
|
||||
// CopySameField 反射自动拷贝同名字段:src(proto入参) → dst(校验model结构体指针)
|
||||
|
||||
Reference in New Issue
Block a user