[ https://issues.apache.org/jira/browse/THRIFT-5859?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17938716#comment-17938716 ]
Duru Can Celasun commented on THRIFT-5859: ------------------------------------------ There are two use cases here, and I don't think they necessarily share the same solution. For enumerating all values, the cleanest approach is returning []Foo. For checking whether a value is valid/defined, I think it's cleaner to have a generated function like: {code:java} func (Foo) IsValid(v Foo) bool { return v==ONE || v==TWO } {code} Or, alternatively: {code:java} var fooKnownValues = map[Foo]bool { ONE: true, TWO: true, } func (Foo) IsValid(v Foo) bool { return fooKnownValues[v] }{code} > go: Generate a map for know values of an enum type > -------------------------------------------------- > > Key: THRIFT-5859 > URL: https://issues.apache.org/jira/browse/THRIFT-5859 > Project: Thrift > Issue Type: Task > Components: Go - Compiler > Affects Versions: 0.21.0 > Reporter: Yuxuan Wang > Assignee: Yuxuan Wang > Priority: Major > Time Spent: 0.5h > Remaining Estimate: 0h > > When an enum type is defined in thrift, in generated go code, there's no way > to enumerate all the known values of the enum type. In most other languages > there's usually a way (via reflecting, access to some private fields, etc.) > to get those. > I propose to also generate a map like: > {code:go} > var FooKnownValues = map[Foo]bool { > ONE: true, > TWO: true, > } > {code} > So it can be used to enumerate all defined values programmatically. > Open to suggestions on the name of the map value :) -- This message was sent by Atlassian Jira (v8.20.10#820010)