relying on compiler for typechecking enums makes code more robust (less errors, typehints, smaller memory footprint, faster execution, better type signatures in functions and structs, compiler detection of collision with other enums/strings).
validating correctness on boundaries of the system (input) ensures that values/types are correct throughout insides of the system
Other
ideally you would wrap enums into structs and codegenerate them like this http://github.com/nikolaydubina/go-enum-encoding, however I see you using tailscape enums without wrapping them in local types, so for now best you can do is to make constructor that validates them
Tests
relying on compiler
please give it a try. I am 99.9% confident this works as expected.
(why I think it works as expected? you don't marshal this field from struct directly. you getting it from the context as string. that's the only entrypoint I can see. typechecker also shows no other usage. thus validating through constructor over there is only place we need to track).
Why?
Other
Tests
(why I think it works as expected? you don't marshal this field from struct directly. you getting it from the context as string. that's the only entrypoint I can see. typechecker also shows no other usage. thus validating through constructor over there is only place we need to track).