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

Method put

cli/pkg/common/http.go:211–249  ·  view source on GitHub ↗
(reqUrl string, reqParams map[string]interface{}, headers map[string]string)

Source from the content-addressed store, hash-verified

209}
210
211func (target HttpClient) put(reqUrl string, reqParams map[string]interface{}, headers map[string]string) (string, error) {
212 jsonBytes, err := json.Marshal(reqParams)
213 if err != nil {
214 return "", err
215 }
216 httpRequest, err := http.NewRequest("PUT", reqUrl, bytes.NewBuffer(jsonBytes))
217 if err != nil {
218 return "", err
219 }
220
221 // client
222 httpClient := getClient(reqUrl, target.TimeOut)
223
224 // 添加请求头
225 headers["Content-Type"] = "application/json" // 后续可根据需要增加其他的类型
226 for k, v := range headers {
227 httpRequest.Header.Add(k, v)
228 }
229
230 // 发送请求
231 SmartIDELog.Debug(formatRequest(httpRequest, reqParams))
232 httpResponse, err := httpClient.Do(httpRequest)
233 if err != nil {
234 return "", err
235 }
236 responseBody, err := parsingResponse(httpResponse)
237 if err != nil {
238 return "", err
239 }
240 defer httpResponse.Body.Close()
241 if httpResponse.StatusCode != 200 {
242 return "", errors.New(httpResponse.Status)
243 }
244 if len(string(responseBody)) == 0 {
245 return "", errors.New("reponse body is empty")
246 }
247 return string(responseBody), err
248
249}
250
251func (target HttpClient) post(reqUrl string,
252 reqParams map[string]interface{}, contentType string, files []UploadFile, headers map[string]string) (

Callers 2

PutMethod · 0.95
JxFunction · 0.80

Calls 5

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

Tested by

no test coverage detected