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

Function parsingResponse

cli/pkg/common/http.go:383–413  ·  view source on GitHub ↗

response format

(resp *http.Response)

Source from the content-addressed store, hash-verified

381
382// response format
383func parsingResponse(resp *http.Response) (string, error) {
384 if resp == nil {
385 return "", errors.New("response is nil")
386 }
387
388 responseBody := []byte{}
389 if resp.Body != nil {
390 responseBody, _ = io.ReadAll(resp.Body)
391 if len(responseBody) == 0 {
392 return "", nil
393 }
394 }
395
396 result := string(responseBody)
397
398 // 压缩json数据,减少打印的信息
399 simpleResult := result
400 regex := regexp.MustCompile(`:".*?[^\\]"`)
401 simpleResult = regex.ReplaceAllStringFunc(simpleResult, func(old string) string {
402 if len(old) > 26 {
403 return old[:23] + "...\""
404 }
405 return old
406 })
407
408 printRespStr := fmt.Sprintf("RESPONSE \n\tcode: %v \n\thead: %v \n\tbody: %s",
409 resp.StatusCode, resp.Header, simpleResult)
410 SmartIDELog.Debug(printRespStr)
411
412 return result, nil
413}
414
415func AddUsernamePassword4ActualGitRpoUrl(actualGitRepoUrl string, gitUsername, gitPassword string) (string, error) {
416 if gitUsername == "" || gitPassword == "" {

Callers 3

getMethod · 0.85
putMethod · 0.85
postMethod · 0.85

Calls 1

DebugMethod · 0.80

Tested by

no test coverage detected