add validator model
CI / changes (push) Successful in 4s
CI / docker-bff (push) Failing after 2s
CI / docker-product (push) Failing after 2s
CI / docker-admin (push) Failing after 2s
CI / docker-user (push) Failing after 2s

This commit is contained in:
2026-08-21 10:53:31 +08:00
parent 736240e8d2
commit 0dbec86c00
6 changed files with 11 additions and 25 deletions
+6
View File
@@ -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结构体指针)