From 1bf555bc4cba45eda48e4519d63a835880898382 Mon Sep 17 00:00:00 2001 From: Manuel Carmona Date: Wed, 12 Apr 2017 12:48:02 +0200 Subject: [PATCH] changed getAlphabeticalOrderedKeys to use sort.Strings --- internal/code-generator/generator/langs.go | 23 ++++++++-------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/internal/code-generator/generator/langs.go b/internal/code-generator/generator/langs.go index 614d246..29e10d7 100644 --- a/internal/code-generator/generator/langs.go +++ b/internal/code-generator/generator/langs.go @@ -3,6 +3,7 @@ package generator import ( "bytes" "io" + "sort" "strings" "text/template" @@ -24,11 +25,7 @@ func Languages(data []byte, languagesTmplPath, languagesTmplName, commit string) return nil, err } - orderedKeyList, err := getAlphabeticalOrderedKeys(data) - if err != nil { - return nil, err - } - + orderedKeyList := getAlphabeticalOrderedKeys(languages) languagesByExtension := buildExtensionLanguageMap(languages, orderedKeyList) buf := &bytes.Buffer{} @@ -39,18 +36,14 @@ func Languages(data []byte, languagesTmplPath, languagesTmplName, commit string) return buf.Bytes(), nil } -func getAlphabeticalOrderedKeys(data []byte) ([]string, error) { - var yamlSlice yaml.MapSlice - if err := yaml.Unmarshal(data, &yamlSlice); err != nil { - return nil, err +func getAlphabeticalOrderedKeys(languages map[string]*languageInfo) []string { + keyList := make([]string, 0) + for lang := range languages { + keyList = append(keyList, lang) } - orderedKeyList := make([]string, 0) - for _, lang := range yamlSlice { - orderedKeyList = append(orderedKeyList, lang.Key.(string)) - } - - return orderedKeyList, nil + sort.Strings(keyList) + return keyList } func buildExtensionLanguageMap(languages map[string]*languageInfo, orderedKeyList []string) map[string][]string {