changed getAlphabeticalOrderedKeys to use sort.Strings

This commit is contained in:
Manuel Carmona 2017-04-12 12:48:02 +02:00
parent 4ed60ad05b
commit 1bf555bc4c

View File

@ -3,6 +3,7 @@ package generator
import ( import (
"bytes" "bytes"
"io" "io"
"sort"
"strings" "strings"
"text/template" "text/template"
@ -24,11 +25,7 @@ func Languages(data []byte, languagesTmplPath, languagesTmplName, commit string)
return nil, err return nil, err
} }
orderedKeyList, err := getAlphabeticalOrderedKeys(data) orderedKeyList := getAlphabeticalOrderedKeys(languages)
if err != nil {
return nil, err
}
languagesByExtension := buildExtensionLanguageMap(languages, orderedKeyList) languagesByExtension := buildExtensionLanguageMap(languages, orderedKeyList)
buf := &bytes.Buffer{} buf := &bytes.Buffer{}
@ -39,18 +36,14 @@ func Languages(data []byte, languagesTmplPath, languagesTmplName, commit string)
return buf.Bytes(), nil return buf.Bytes(), nil
} }
func getAlphabeticalOrderedKeys(data []byte) ([]string, error) { func getAlphabeticalOrderedKeys(languages map[string]*languageInfo) []string {
var yamlSlice yaml.MapSlice keyList := make([]string, 0)
if err := yaml.Unmarshal(data, &yamlSlice); err != nil { for lang := range languages {
return nil, err keyList = append(keyList, lang)
} }
orderedKeyList := make([]string, 0) sort.Strings(keyList)
for _, lang := range yamlSlice { return keyList
orderedKeyList = append(orderedKeyList, lang.Key.(string))
}
return orderedKeyList, nil
} }
func buildExtensionLanguageMap(languages map[string]*languageInfo, orderedKeyList []string) map[string][]string { func buildExtensionLanguageMap(languages map[string]*languageInfo, orderedKeyList []string) map[string][]string {