Re:Show HN: A utility for running exhaustiveness checks on “...
by aston on Monday March 20, 2017 @05:03PM
(#13917630)
You may want to take a look at https://github.com/alvaroloes/enumer which can generate functions around your enum to give/accept string representations, plus JSON and SQL scanning.
Although my described approaches aren't great, I'm glad to see people thinking about how to improve it with tooling. For reference, this is the same thing in Haskell:
I really prefer this format because the set of possible Person type options is explicitly defined and easy to exhaustively check. You'll get no type coercion from arbitrary strings like "Daughter".And you can also extra data types using type constructors:
At least by attempting to use sum types in Go, you get some compiler checks, which are a lot better than none.Has anyone figured out a better way?
[1] https://github.com/kubernetes/kubernetes/blob/master/pkg/api...
[2] https://github.com/campoy/jsonenums