mycommon/myvalidator/validator_gin.go

23 lines
408 B
Go
Raw Normal View History

2023-01-15 00:21:08 +08:00
package myvalidator
import (
ut "github.com/go-playground/universal-translator"
"github.com/go-playground/validator/v10"
)
var (
ginTrans ut.Translator
)
func InitGin(ginVt *validator.Validate) {
//if vt2, ok := binding.Validator.Engine().(*validator.Validate); ok {
// ginVt = vt2
//}
ginTrans = RegisterTranslate(ginVt)
}
func TransGin(err error) error {
return GetTransError(ginTrans, err)
}