From e70ccb6e743f48abe70bdcd15c9b438c1cdf4247 Mon Sep 17 00:00:00 2001 From: mcorbin Date: Fri, 1 Jul 2022 22:48:57 +0200 Subject: [PATCH] fix: make sure a validator exists In the RegisterTagNameFunc make sure the validator exists, before trying to assign a func to it. Also updated comment to fix small typos. https://github.com/loopfz/gadgeto/pull/75 --- tonic/handler.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tonic/handler.go b/tonic/handler.go index 6664bc6..c104823 100644 --- a/tonic/handler.go +++ b/tonic/handler.go @@ -154,7 +154,7 @@ func RegisterValidation(tagName string, validationFunc validator.Func) error { // // eg. to use the names which have been specified for JSON representations of structs, rather than normal Go field names: // -// validate.RegisterTagNameFunc(func(fld reflect.StructField) string { +// tonic.RegisterTagNameFunc(func(fld reflect.StructField) string { // name := strings.SplitN(fld.Tag.Get("json"), ",", 2)[0] // if name == "-" { // return "" @@ -162,6 +162,7 @@ func RegisterValidation(tagName string, validationFunc validator.Func) error { // return name // } func RegisterTagNameFunc(registerTagFunc validator.TagNameFunc) { + initValidator() validatorObj.RegisterTagNameFunc(registerTagFunc) }