8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
System (please complete the following information):
linux
1.19
1.4.4
Describe the bug
I would like to apply the string trim filter to each element in a slice.
For example with input {" hello ", " test", "test2 "} I would like output {"hello", "test", "test2"}.
{" hello ", " test", "test2 "}
{"hello", "test", "test2"}
To Reproduce
I have made a Go Playground where I tried using the existing StringRule, but this didn't work. https://go.dev/play/p/4GiKMauL0hn
StringRule
// You can edit this code! // Click here and start typing. package main import ( "log" "github.com/gookit/validate" ) type Foo struct { Domains []string } func (gs Foo) ConfigValidation(v *validate.Validation) { v.StringRule("Domains.*", "trim") } func main() { f := Foo{Domains: []string{" test.com ", "oof.com", " foobar.com"}} v := validate.Struct(&f) // nolint:varnamelen if !v.Validate() { log.Println(v.Errors) } log.Println(f) }
Output is: panic: validate: the validator 'trim' does not exist
panic: validate: the validator 'trim' does not exist
Expected behavior
I would expect the whitespace to be trimmed and the output to look like: Output is: {[test.com oof.com foobar.com]}
{[test.com oof.com foobar.com]}
The text was updated successfully, but these errors were encountered:
087269d
Thanks, the trimStrings filter achieved what I wanted! Thanks for the test case in the MR which showed how to achieve this.
Sorry, something went wrong.
inhere
No branches or pull requests
System (please complete the following information):
linux
1.19
1.4.4
Describe the bug
I would like to apply the string trim filter to each element in a slice.
For example with input
{" hello ", " test", "test2 "}
I would like output{"hello", "test", "test2"}
.To Reproduce
I have made a Go Playground where I tried using the existing
StringRule
, but this didn't work.https://go.dev/play/p/4GiKMauL0hn
Output is:
panic: validate: the validator 'trim' does not exist
Expected behavior
I would expect the whitespace to be trimmed and the output to look like: Output is:
{[test.com oof.com foobar.com]}
The text was updated successfully, but these errors were encountered: