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.
Changes
validate
flagvalidate
flag is true, generate aValidate() error
method that verifies the enum is set to a proper valueWhy
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 anerror
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 usingerrors.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.