MCPcopy Create free account
hub / github.com/go-dev-frame/sponge / gDo

Function gDo

pkg/httpcli/httpcli.go:457–487  ·  view source on GitHub ↗
(method string, result interface{}, urlStr string, params KV, headers map[string]string, timeout time.Duration)

Source from the content-addressed store, hash-verified

455}
456
457func gDo(method string, result interface{}, urlStr string, params KV, headers map[string]string, timeout time.Duration) error {
458 req := &Request{}
459 req.SetURL(urlStr)
460 req.SetParams(params)
461 req.SetHeaders(headers)
462 req.SetTimeout(timeout)
463
464 var resp *Response
465 var err error
466 switch method {
467 case "GET":
468 resp, err = req.GET()
469 case "DELETE":
470 resp, err = req.DELETE()
471 }
472 if err != nil {
473 return requestErr(err)
474 }
475 defer resp.Body.Close() //nolint
476
477 if resp.StatusCode != 200 {
478 return notOKErr(resp)
479 }
480
481 err = resp.BindJSON(result)
482 if err != nil {
483 return jsonParseErr(err)
484 }
485
486 return nil
487}
488
489// StdResult standard return data
490type StdResult struct {

Callers 3

GetFunction · 0.85
DeleteFunction · 0.85
TestErrorFunction · 0.85

Calls 8

SetURLMethod · 0.95
SetParamsMethod · 0.95
SetHeadersMethod · 0.95
SetTimeoutMethod · 0.95
GETMethod · 0.95
DELETEMethod · 0.95
BindJSONMethod · 0.95
CloseMethod · 0.65

Tested by 1

TestErrorFunction · 0.68