-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
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
Does not work with *int ? #250
Comments
[Edit] Sorry, should have known, private fields are not validated. Narrowed it down to visibility of fields: package main
import (
"fmt"
"github.com/davecgh/go-spew/spew"
"github.com/gookit/validate"
)
// Works
type A struct {
a *int `validate:"min:1"`
}
// Doesn't work
type B struct {
B *int `validate:"min:1"`
}
func main() {
i := 3
// Works
pa := A{a: &i}
va := validate.Struct(pa)
spew.Dump(va)
if va.Validate() {
fmt.Println("Ok!")
} else {
fmt.Println("Not ok!")
spew.Dump(va.Errors)
}
// Doesn't work
p := B{B: &i}
v := validate.Struct(p)
spew.Dump(p)
if v.Validate() {
fmt.Println("Ok!")
} else {
fmt.Println("Not ok!")
spew.Dump(v.Errors)
}
} go.mod
|
Wasn't clear in my last comment. How would I model optional numbers? *int does not work. A1 int `validate:"int|min:200"`" validates to ok with 0 but fails with 100. Couldn't find that in the documentation. Is this how to model optional ints? package main
import (
"fmt"
"github.com/davecgh/go-spew/spew"
"github.com/gookit/validate"
)
type A struct {
A1 *int `validate:"int|min:200"`
A2 *int `validate:"int|min:200"`
}
func main() {
i := 3
// Works
pa := A{A1: &i, A2: nil}
va := validate.Struct(pa)
spew.Dump(pa)
if va.Validate() {
fmt.Println("Ok!")
} else {
fmt.Println("Not ok!")
fmt.Println(va.Errors.One())
spew.Dump(va.Errors)
}
} results in
|
@StephanSchmidt please see test: Lines 1602 to 1651 in ab0111b
It's OK? |
With github.com/gookit/validate v1.5.1
I use
With the data
and get on validation this error:
Does *int not work as a field? How would I encode optional ints?
The text was updated successfully, but these errors were encountered: