@@ -4,8 +4,10 @@ import "fmt"
4
4
5
5
// Arguments to format are:
6
6
// [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 {
9
11
return val, nil
10
12
}
11
13
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) {
14
16
15
17
func (g * Generator ) buildValueToNameMap (runs [][]Value , typeName string , runsThreshold int ) {
16
18
// At this moment, either "g.declareIndexAndNameVars()" or "g.declareNameVars()" has been called
17
- g .Printf ("\n var _%sNameToValue_map = map[string]%s{\n " , typeName , typeName )
19
+ g .Printf ("\n var _%sNameToValueMap = map[string]%s{\n " , typeName , typeName )
18
20
thereAreRuns := len (runs ) > 1 && len (runs ) <= runsThreshold
19
21
var n int
20
22
var runID string
@@ -27,7 +29,7 @@ func (g *Generator) buildValueToNameMap(runs [][]Value, typeName string, runsThr
27
29
}
28
30
29
31
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 )
31
33
n += len (value .name )
32
34
}
33
35
}
0 commit comments