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

Commit

Permalink
move the generic helper func to cloudstack file
Browse files Browse the repository at this point in the history
  • Loading branch information
nettoclaudio committed Mar 31, 2020
1 parent 577329d commit fd791a0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
9 changes: 0 additions & 9 deletions cloudstack/ResourcetagsService.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,10 @@ import (
"encoding/json"
"fmt"
"net/url"
"sort"
"strconv"
"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
9 changes: 9 additions & 0 deletions cloudstack/cloudstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,15 @@ func getRawValue(b json.RawMessage) (json.RawMessage, error) {
return nil, fmt.Errorf("Unable to extract the raw value from:\n\n%s\n\n", string(b))
}

// getSortedKeysFromMap returns the keys from m in increasing order.
func getSortedKeysFromMap(m map[string]string) (keys []string) {
for k := range m {
keys = append(keys, k)
}
sort.Strings(keys)
return
}

// WithAsyncTimeout takes a custom timeout to be used by the CloudStackClient
func WithAsyncTimeout(timeout int64) ClientOption {
return func(cs *CloudStackClient) {
Expand Down
18 changes: 9 additions & 9 deletions generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,15 @@ func (as *allServices) GeneralCode() ([]byte, error) {
pn(" return nil, fmt.Errorf(\"Unable to extract the raw value from:\\n\\n%%s\\n\\n\", string(b))")
pn("}")
pn("")
pn("// getSortedKeysFromMap returns the keys from m in increasing order.")
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("}")
pn("")
pn("// WithAsyncTimeout takes a custom timeout to be used by the CloudStackClient")
pn("func WithAsyncTimeout(timeout int64) ClientOption {")
pn(" return func(cs *CloudStackClient) {")
Expand Down Expand Up @@ -832,15 +841,6 @@ 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 fd791a0

Please sign in to comment.