Generate string to enum using stringer.

323 views
Skip to first unread message

tamal

unread,
Feb 10, 2017, 2:35:57 AM2/10/17
to golang-nuts
Hi,
We would like to be able to generate string to enum value method using stringer in addition to String() method.

Is this something that can be added to Stringer? If yes, what is the process for that?

Thanks.

howar...@gmail.com

unread,
Feb 15, 2017, 9:14:06 AM2/15/17
to golang-nuts
It already has been! Álvaro has done this for you. https://github.com/alvaroloes/enumer

This is a fork of stringer that has the function you want:
  • A function <Type>String(s string) to get the enum value from its string representation. This is useful when you need to read enum values from command line arguments, from a configuration file, or from a REST API request... In short, from those places where using the real enum value (an integer) would be almost meaningless or hard to trace or use by a human.
Reply all
Reply to author
Forward
0 new messages