Skip to content

Commit aa50e29

Browse files
committed
Added comment to generated ...String function. Removed usage of _ in identifiers.
1 parent fbb114e commit aa50e29

File tree

3 files changed

+248
-241
lines changed

3 files changed

+248
-241
lines changed

enumer.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import "fmt"
44

55
// Arguments to format are:
66
// [1]: type name
7-
const stringValueToNameMap = `func %[1]sString(s string) (%[1]s, error) {
8-
if val, ok := _%[1]sNameToValue_map[s]; ok {
7+
const stringValueToNameMap = `// %[1]sString retrieves an enum value from the enum constants string name.
8+
// Throws an error if the param is not part of the enum.
9+
func %[1]sString(s string) (%[1]s, error) {
10+
if val, ok := _%[1]sNameToValueMap[s]; ok {
911
return val, nil
1012
}
1113
return 0, fmt.Errorf("%%s does not belong to %[1]s values", s)
@@ -14,7 +16,7 @@ const stringValueToNameMap = `func %[1]sString(s string) (%[1]s, error) {
1416

1517
func (g *Generator) buildValueToNameMap(runs [][]Value, typeName string, runsThreshold int) {
1618
// At this moment, either "g.declareIndexAndNameVars()" or "g.declareNameVars()" has been called
17-
g.Printf("\nvar _%sNameToValue_map = map[string]%s{\n", typeName, typeName)
19+
g.Printf("\nvar _%sNameToValueMap = map[string]%s{\n", typeName, typeName)
1820
thereAreRuns := len(runs) > 1 && len(runs) <= runsThreshold
1921
var n int
2022
var runID string
@@ -27,7 +29,7 @@ func (g *Generator) buildValueToNameMap(runs [][]Value, typeName string, runsThr
2729
}
2830

2931
for _, value := range values {
30-
g.Printf("\t_%s_name%s[%d:%d]: %s,\n", typeName, runID, n, n+len(value.name), &value)
32+
g.Printf("\t_%sName%s[%d:%d]: %s,\n", typeName, runID, n, n+len(value.name), &value)
3133
n += len(value.name)
3234
}
3335
}

0 commit comments

Comments
 (0)