Skip to content

Commit

Permalink
fix: make sure a validator exists
Browse files Browse the repository at this point in the history
In the RegisterTagNameFunc make sure the validator exists,
before trying to assign a func to it. Also updated comment to fix small typos.

loopfz#75
  • Loading branch information
mcorbin committed Jul 1, 2022
1 parent 6a18fff commit e70ccb6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tonic/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,15 @@ 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 ""
// }
// return name
// }
func RegisterTagNameFunc(registerTagFunc validator.TagNameFunc) {
initValidator()
validatorObj.RegisterTagNameFunc(registerTagFunc)
}

Expand Down

0 comments on commit e70ccb6

Please sign in to comment.