Closed silmin closed 2 years ago
Hi! I'm trying to implement a Validate() method on a struct and I'm trying to use a custom validator, but I've come across strange behavior.
Validate()
When I execute the following code, the validation works again and the stack overflows.
func main() { var foo Foo foo.str = "foo" foo.Validate() } type Foo struct { str string } func (a Foo) Validate() error { return validation.Validate(a, validation.By(checkFoo)) } func checkFoo(i interface{}) error { foo, _ := i.(Foo) fmt.Println(foo) if foo.str != "foo" { return fmt.Errorf("must be foo") } return nil }
On The Go Playground, I got timeout error with many {foo} https://go.dev/play/p/fMiGwDUiIMN?v=goprev
{foo}
But if I comment out fmt.Println(foo) on checkFoo() this works fine.
fmt.Println(foo)
checkFoo()
I didn't know the cause. What the hell is this? Is it a bug?
Thank you.
I feel like I understand the cause, so I will close it. I'll implement ValidateStruct() .
ValidateStruct()
Hi! I'm trying to implement a
Validate()
method on a struct and I'm trying to use a custom validator, but I've come across strange behavior.When I execute the following code, the validation works again and the stack overflows.
On The Go Playground, I got timeout error with many
{foo}
https://go.dev/play/p/fMiGwDUiIMN?v=goprevBut if I comment out
fmt.Println(foo)
oncheckFoo()
this works fine.I didn't know the cause. What the hell is this? Is it a bug?
Thank you.