MCPcopy Create free account
hub / github.com/OpenAtomFoundation/SmartIDE / get

Method get

cli/pkg/common/http.go:166–209  ·  view source on GitHub ↗

* func SetTimeOut(timeDuration time.Duration) { if timeDuration != 0 { defaultTimeout = timeDuration } } */

(reqUrl string, reqParams map[string]string, headers map[string]string)

Source from the content-addressed store, hash-verified

164} */
165
166func (target HttpClient) get(reqUrl string, reqParams map[string]string, headers map[string]string) (string, error) {
167 urlParams := url.Values{}
168 Url, _ := url.Parse(reqUrl)
169 for key, val := range reqParams {
170 urlParams.Set(key, val)
171 }
172
173 // client
174 httpClient := getClient(reqUrl, target.TimeOut)
175
176 //如果参数中有中文参数,这个方法会进行URLEncode
177 Url.RawQuery = urlParams.Encode()
178 // 得到完整的url,http://xx?query
179 urlPath := Url.String()
180
181 httpRequest, err := http.NewRequest("GET", urlPath, nil)
182 if err != nil {
183 return "", err
184 }
185 // 添加请求头
186 for k, v := range headers {
187 httpRequest.Header.Add(k, v)
188 }
189
190 // 发送请求
191 SmartIDELog.Debug(formatRequest(httpRequest, nil))
192 httpResponse, err := httpClient.Do(httpRequest)
193 if err != nil {
194 return "", err
195 }
196 responseBody, err := parsingResponse(httpResponse)
197 if err != nil {
198 return "", err
199 }
200 defer httpResponse.Body.Close()
201 if httpResponse.StatusCode != 200 {
202 return "", errors.New(httpResponse.Status)
203 }
204
205 if len(string(responseBody)) == 0 {
206 return "", errors.New("reponse body is empty")
207 }
208 return string(responseBody), nil
209}
210
211func (target HttpClient) put(reqUrl string, reqParams map[string]interface{}, headers map[string]string) (string, error) {
212 jsonBytes, err := json.Marshal(reqParams)

Callers 15

GetMethod · 0.95
leFunction · 0.80
yeFunction · 0.80
AeFunction · 0.80
OeFunction · 0.80
aFunction · 0.80
irFunction · 0.80
IiFunction · 0.80
PiFunction · 0.80
MsFunction · 0.80
yFunction · 0.80

Calls 6

getClientFunction · 0.85
formatRequestFunction · 0.85
parsingResponseFunction · 0.85
DebugMethod · 0.80
DoMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected