MCPcopy Create free account
hub / github.com/cli/cli / addQueryParam

Function addQueryParam

pkg/cmd/api/http.go:122–151  ·  view source on GitHub ↗
(query url.Values, key string, value interface{})

Source from the content-addressed store, hash-verified

120}
121
122func addQueryParam(query url.Values, key string, value interface{}) error {
123 switch v := value.(type) {
124 case string:
125 query.Add(key, v)
126 case []byte:
127 query.Add(key, string(v))
128 case nil:
129 query.Add(key, "")
130 case int:
131 query.Add(key, fmt.Sprintf("%d", v))
132 case bool:
133 query.Add(key, fmt.Sprintf("%v", v))
134 case map[string]interface{}:
135 for subkey, value := range v {
136 // support for nested subkeys can be added here if that is ever necessary
137 if err := addQueryParam(query, subkey, value); err != nil {
138 return err
139 }
140 }
141 case []interface{}:
142 for _, entry := range v {
143 if err := addQueryParam(query, key+"[]", entry); err != nil {
144 return err
145 }
146 }
147 default:
148 return fmt.Errorf("unknown type %v", v)
149 }
150 return nil
151}

Callers 1

addQueryFunction · 0.85

Calls 2

AddMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected