Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Send map API types in a predictable order (sorted by key name)
Browse files Browse the repository at this point in the history
  • Loading branch information
nettoclaudio authored and psycofdj committed Jan 22, 2021
1 parent 6c49a69 commit 96c5f36
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
17 changes: 8 additions & 9 deletions cloudstack/ResourcetagsService.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ import (
"strings"
)

func getSortedKeysFromMap(m map[string]string) (keys []string) {
for k := range m {
keys = append(keys, k)
}
sort.Strings(keys)
return
}

type CreateTagsParams struct {
p map[string]interface{}
}
Expand Down Expand Up @@ -528,12 +536,3 @@ type Tag struct {
Resourcetype string `json:"resourcetype"`
Value string `json:"value"`
}

func getSortedKeysFromMap(m map[string]string) []string {
var keys []string
for k := range m {
keys = append(keys, k)
}
sort.Strings(keys)
return keys
}
9 changes: 9 additions & 0 deletions generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,15 @@ func (s *service) GenerateCode() ([]byte, error) {
pn(" return json.Unmarshal(resp, result)")
pn("}")
}
if s.name == "ResourcetagsService" {
pn("func getSortedKeysFromMap(m map[string]string) (keys []string) {")
pn(" for k := range m {")
pn(" keys = append(keys, k)")
pn(" }")
pn(" sort.Strings(keys)")
pn(" return")
pn("}")
}

for _, a := range s.apis {
s.generateParamType(a)
Expand Down

0 comments on commit 96c5f36

Please sign in to comment.