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

Add optional "Validate() error" method #82

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mbyio
Copy link

@mbyio mbyio commented Dec 2, 2023

Changes

  • Add a new validate flag
  • When the validate flag is true, generate a Validate() error method that verifies the enum is set to a proper value
  • Some small quality of life improvements to the golden test runner
  • Run gofmt on some of the files (this just happened automatically because of my editor)

Why

We currently have a IsA<Type>() bool method, but the name is different for every enum type. That basically makes it impossible to integrate it with Go interfaces or generics.

I return an error instead of a bool, because returning an error lets us provide more information on why the value is invalid. And again, it would also compose better with any generic validation code (you could, for example, recursively validate fields in a struct, and combine all the errors using errors.Join).

Note

I didn't see any more well known method signatures than Validate() error, but if there are any, we could switch and use that instead.

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.

None yet

1 participant