MCPcopy
hub / github.com/cli/cli / addQueryParam

Function addQueryParam

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

Source from the content-addressed store, hash-verified

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

Callers 1

addQueryFunction · 0.85

Calls 2

AddMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected