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

Function addQueryParam

pkg/cmd/api/http.go:131–160  ·  view source on GitHub ↗
(query url.Values, key string, value any)

Source from the content-addressed store, hash-verified

129}
130
131func addQueryParam(query url.Values, key string, value any) error {
132 switch v := value.(type) {
133 case string:
134 query.Add(key, v)
135 case []byte:
136 query.Add(key, string(v))
137 case nil:
138 query.Add(key, "")
139 case int:
140 query.Add(key, fmt.Sprintf("%d", v))
141 case bool:
142 query.Add(key, fmt.Sprintf("%v", v))
143 case map[string]any:
144 for subkey, value := range v {
145 // support for nested subkeys can be added here if that is ever necessary
146 if err := addQueryParam(query, subkey, value); err != nil {
147 return err
148 }
149 }
150 case []any:
151 for _, entry := range v {
152 if err := addQueryParam(query, key+"[]", entry); err != nil {
153 return err
154 }
155 }
156 default:
157 return fmt.Errorf("unknown type %v", v)
158 }
159 return nil
160}
161
162// swapURLHost replaces the host component of rawURL with newHost, preserving
163// scheme, port (if already present in rawURL), path, and query unchanged.

Callers 1

addQueryFunction · 0.85

Calls 2

AddMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected