New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we assign custom names to enum values ? #25

Open
taherv opened this Issue Nov 12, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@taherv

taherv commented Nov 12, 2017

type Fruit int
const (
     Apple Fruit = iota
     Banana
     Orange
)

I'd like the strings to be "apple", "banana", "orange". How can I assign custom strings ?

Something like this would work ?

type Fruit int
const (
     Apple Fruit = iota  `"apple"`
     Banana                  `"banana"`
     Orange                  `"orange"`
)
@taherv

This comment has been minimized.

Show comment
Hide comment
@taherv

taherv Nov 12, 2017

Also, for other reasons, I also need to implement stringer for my type, should jsonenums also generate the String() function ?

taherv commented Nov 12, 2017

Also, for other reasons, I also need to implement stringer for my type, should jsonenums also generate the String() function ?

@dmitshur

This comment has been minimized.

Show comment
Hide comment
@dmitshur

dmitshur Nov 12, 2017

Contributor

I also need to implement stringer for my type

There exists stringer for that task. (But I don’t think it’s output is customizable.)

Contributor

dmitshur commented Nov 12, 2017

I also need to implement stringer for my type

There exists stringer for that task. (But I don’t think it’s output is customizable.)

@taherv

This comment has been minimized.

Show comment
Hide comment
@taherv

taherv Nov 12, 2017

I found this project https://github.com/alvaroloes/enumer
It generates yaml/json marshalers and also stringer implementations all using the same strings for enums.
It has basic string customization support (they call it "transform") which does what I want (small case strings) but it is not generally customizable as I would have expected ..... it does the job for me in the time being

taherv commented Nov 12, 2017

I found this project https://github.com/alvaroloes/enumer
It generates yaml/json marshalers and also stringer implementations all using the same strings for enums.
It has basic string customization support (they call it "transform") which does what I want (small case strings) but it is not generally customizable as I would have expected ..... it does the job for me in the time being

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment