From 557860435bb41336e1eee0917ce07eb508c4e12f Mon Sep 17 00:00:00 2001 From: Dmytro Nochevnov Date: Wed, 27 Nov 2019 11:48:47 +0200 Subject: [PATCH] Order the map when converting it to a string (#133) Signed-off-by: David Festal --- pkg/util/util.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/util/util.go b/pkg/util/util.go index fd558b205..12873a623 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -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(), ",") }