Skip to content

[generate] If base type of enum is string, String() should return the original value #2

Description

@neglect-yp
// enumizer:target
type Color string

const (
    Red   Color = "red"
    Green Color = "green"
    Blue  Color = "blue"
)

If base type of enum is string like Color, String() should be as follows:

func String(c Color) string {
    switch c {
        case Red, Green, Blue:
            return string(c)
        default:
            return "unknown Color"
    }
}

If the value and String() result are different, users will be confused.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions