From bf99c1afad12dc9c343f4fddb774c998fb308801 Mon Sep 17 00:00:00 2001 From: Bhargav Ravuri Date: Sat, 19 Nov 2022 21:55:53 +0530 Subject: [PATCH] Print Default Values of String-to-String in Sorted Order Signed-off-by: Bhargav Ravuri --- string_to_string.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/string_to_string.go b/string_to_string.go index 890a01af..1d1e3bf9 100644 --- a/string_to_string.go +++ b/string_to_string.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/csv" "fmt" + "sort" "strings" ) @@ -62,8 +63,15 @@ func (s *stringToStringValue) Type() string { } func (s *stringToStringValue) String() string { + keys := make([]string, 0, len(*s.value)) + for k := range *s.value { + keys = append(keys, k) + } + sort.Strings(keys) + records := make([]string, 0, len(*s.value)>>1) - for k, v := range *s.value { + for _, k := range keys { + v := (*s.value)[k] records = append(records, k+"="+v) }