Skip to content
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

Min() validator fails on uint32 field #51

Closed
mklimuk opened this issue Jul 26, 2018 · 2 comments
Closed

Min() validator fails on uint32 field #51

mklimuk opened this issue Jul 26, 2018 · 2 comments

Comments

@mklimuk
Copy link

mklimuk commented Jul 26, 2018

I stumbled upon this when trying to validate a struct with uint32 field. The validation fails with

Integer: cannot convert uint32 to int64.

Here's a complete test case:

package main

import (
	"fmt"
	"testing"

	"github.com/go-ozzo/ozzo-validation"
)

type A struct {
	Integer uint32
}

func (a A) Validate() error {
	return validation.ValidateStruct(&a,
		validation.Field(&a.Integer, validation.Required, validation.Min(1)))
}

func TestValidate(t *testing.T) {
	a := A{2}
	err := a.Validate()
	if err != nil {
		fmt.Printf("validation error received: %s", err.Error())
		t.Fail()
	}
}
@mklimuk
Copy link
Author

mklimuk commented Jul 26, 2018

After some digging in I suppose the error is due to the fact that Indirect(value interface{}) (interface{}, bool) method does not resolve pointers to uint32 properly. I'll try to issue a PR if I manage to fix the issue.

@mklimuk
Copy link
Author

mklimuk commented Jul 26, 2018

Ok, my bad. It just requires to set the validator value in the target type. So validation.Min(uint32(1)) fixed it for me. Closing...

@mklimuk mklimuk closed this as completed Jul 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant