alvaroloes / enumer

A Go tool to auto generate methods for your enums
Other
478 stars 111 forks source link

Enum value string representation transformation feature #6

Closed THE108 closed 7 years ago

THE108 commented 7 years ago

Stringer tool uses the same name for enum value string representation (usually CamelCase in Go).

type MyType int

 ...

name := MyTypeValue.String() // name => "MyTypeValue"

Sometimes you need to use some other string representation format then CamelCase (i.e. in JSON).

To transform enum value string representation from CamelCase to snake_case or kebab-case transform flag could be used.

For example, for enumer -type=MyType -json -transform=snake command the next string representation will be generated:

name := MyTypeValue.String() // name => "my_type_value"
alvaroloes commented 7 years ago

Hey @THE108. Thank you very much!

Not only for the funcionality, but for including tests and all the other "little touches" (like the .gitignore and corrections in the Readme)

I'll merge this (I will just fix some typos in the new text added to the Readme 😉 )

Happy coding!