From 67c61e436f4bf250b03091496d05965ae91c1a3c Mon Sep 17 00:00:00 2001 From: BenTrapani Date: Fri, 29 Jul 2016 15:29:21 -0400 Subject: [PATCH] Create map to hold both cases and populate --- jsonenums.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/jsonenums.go b/jsonenums.go index 60346ee..26ad50b 100644 --- a/jsonenums.go +++ b/jsonenums.go @@ -75,7 +75,7 @@ import ( "path/filepath" "strings" - "github.com/campoy/jsonenums/parser" + "github.com/BenjaminTrapani/jsonenums/parser" ) var ( @@ -84,6 +84,11 @@ var ( outputSuffix = flag.String("suffix", "_jsonenums", "suffix to be added to the output file") ) +type CammelSnakePair struct { + CammelRep string + SnakeRep string +} + func main() { flag.Parse() if len(*typeNames) == 0 { @@ -112,11 +117,11 @@ func main() { var analysis = struct { Command string PackageName string - TypesAndValues map[string][]string + TypesAndValues map[string][]CammelSnakePair }{ Command: strings.Join(os.Args[1:], " "), PackageName: pkg.Name, - TypesAndValues: make(map[string][]string), + TypesAndValues: make(map[string][]CammelSnakePair), } // Run generate for each type. @@ -125,7 +130,14 @@ func main() { if err != nil { log.Fatalf("finding values for type %v: %v", typeName, err) } - analysis.TypesAndValues[typeName] = values + + cammelSnakePairs := make([]CammelSnakePair, len(values)) + for i, value := range values { + cammelSnakePairs[i].CammelRep = value + cammelSnakePairs[i].SnakeRep = ToSnake(value) + } + + analysis.TypesAndValues[typeName] = cammelSnakePairs var buf bytes.Buffer if err := generatedTmpl.Execute(&buf, analysis); err != nil {