29 lines
518 B
Go
29 lines
518 B
Go
package validator
|
|
|
|
import (
|
|
"gopkg.in/go-playground/validator.v9"
|
|
"nos-comptes/internal/storage/validators"
|
|
"reflect"
|
|
"strings"
|
|
)
|
|
|
|
func newValidator() *validator.Validate {
|
|
va := validator.New()
|
|
|
|
va.RegisterTagNameFunc(func(fld reflect.StructField) string {
|
|
name := strings.SplitN(fld.Tag.Get("json"), ",", 2)
|
|
if len(name) < 1 {
|
|
return ""
|
|
}
|
|
return name[0]
|
|
})
|
|
|
|
for k, v := range validators.CustomValidators {
|
|
if v.Validator != nil {
|
|
va.RegisterValidationCtx(k, v.Validator)
|
|
}
|
|
}
|
|
|
|
return va
|
|
}
|