Created
October 14, 2016 23:31
-
-
Save ducc/9e229c7e9e89a24e3efca1ea8fa757d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"reflect" | |
) | |
type MyEnum struct { | |
SOME_VALUE string | |
SOME_OTHER_THING string | |
} | |
func (enum MyEnum) values() []string { | |
val := reflect.Indirect(reflect.ValueOf(enum)) | |
array := make([]string, val.NumField()) | |
for i := 0; i < val.NumField(); i++ { | |
fVal := val.Field(i) | |
array[i] = fVal.String() | |
} | |
return array | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment