rano/util/validate/validate.go
Ankit Patial 26a00c9f7c working on auth.
mailer, basic setup with html template and a dev treansport
2024-11-15 21:42:15 +05:30

27 lines
464 B
Go

package validate
import (
"reflect"
"strings"
"github.com/go-playground/validator/v10"
)
var validate *validator.Validate
func init() {
validate = validator.New()
// register function to get tag name from json tags.
validate.RegisterTagNameFunc(func(fld reflect.StructField) string {
name := strings.SplitN(fld.Tag.Get("json"), ",", 2)[0]
if name == "-" {
return ""
}
return name
})
}
func Struct(s any) error {
return validate.Struct(s)
}