Skip to content

Conversation

@goodevilgenius
Copy link

Similar to #24, but this adds an Is method to ErrorObject. This allows us, in conjunction with #24, to do something like this:

type Stuff struct {
	Name string
}

func (st Stuff) Validate() error {
	return validation.ValidateStruct(
		&st,
		validation.Field(&st.Name, validation.Lenth(1, 5)),
	)
}

func main() {
	st := Stuff{}
	err := st.Validate()
	fmt.Println(err)
	if errors.Is(err, validation.ErrLengthOutOfRange) {
		fmt.Println("this stuff is the wrong size")
	} else {
		fmt.Println("this stuff is the right size")
	}
}

Copy link

@swithek swithek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks 👍

@swithek swithek merged commit 4048dd2 into jellydator:master Oct 1, 2025
2 checks passed
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

Successfully merging this pull request may close these issues.

2 participants