Order the map when converting it to a string (#133)

Signed-off-by: David Festal <dfestal@redhat.com>
pull/135/head
Dmytro Nochevnov 2019-11-27 11:48:47 +02:00 committed by GitHub
parent 76ba7b516b
commit 557860435b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 2 deletions

View File

@ -12,6 +12,7 @@
package util
import (
"sort"
"crypto/tls"
"encoding/json"
"errors"
@ -65,8 +66,16 @@ func GeneratePasswd(stringLength int) (passwd string) {
func MapToKeyValuePairs(m map[string]string) string {
buff := new(bytes.Buffer)
for key, value := range m {
fmt.Fprintf(buff, "%s=%s,", key, value)
keys := make([]string, 0, len(m))
for key := range m {
keys = append(keys, key)
}
sort.Strings(keys) //sort keys alphabetically
for _, key := range keys {
fmt.Fprintf(buff, "%s=%s,", key, m[key])
}
return strings.TrimSuffix(buff.String(), ",")
}