Alter the value in custom validation function? #957
Answered
by
deankarn
ItalyPaleAle
asked this question in
Q&A
-
Is there a way to alter the value in a custom validation function? I need to write validators that do not just accept or reject a value, but alter it, sanitizing the value or modifying it in other ways (for example, I need to "normalize" the Unicode form of certain strings). I tried things like: d.validate.RegisterValidationCtx("myvalidator", func(ctx context.Context, fl validator.FieldLevel) bool {
fl.Field().SetString("newvalue")
return true
}, false) But this is causing a panic as, it seems, |
Beta Was this translation helpful? Give feedback.
Answered by
deankarn
Jun 3, 2022
Replies: 1 comment 1 reply
-
No this is jot possible using validator for multiple reasons, please see/search for the multiple closed issues asking the same :) For sanitization, prior to validation, this library exists https://github.com/go-playground/mold |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
ItalyPaleAle
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No this is jot possible using validator for multiple reasons, please see/search for the multiple closed issues asking the same :)
For sanitization, prior to validation, this library exists https://github.com/go-playground/mold