MCPcopy Create free account
hub / github.com/deepflowio/deepflow / CURLPerform

Function CURLPerform

cli/ctl/common/http_util.go:66–98  ·  view source on GitHub ↗

功能:调用其他模块API并获取返回结果

(method string, url string, body map[string]interface{}, strBody string, opts ...HTTPOption)

Source from the content-addressed store, hash-verified

64
65// 功能:调用其他模块API并获取返回结果
66func CURLPerform(method string, url string, body map[string]interface{}, strBody string, opts ...HTTPOption) (*simplejson.Json, error) {
67 cfg := &HTTPConf{}
68 for _, opt := range opts {
69 opt(cfg)
70 }
71
72 var err error
73 var contentType string
74 req := &http.Request{}
75 if strBody != "" {
76 reader := strings.NewReader(strBody)
77 req, err = http.NewRequest(method, url, reader)
78 contentType = "application/x-www-form-urlencoded"
79 } else {
80 bodyStr, _ := json.Marshal(&body)
81 reader := bytes.NewReader(bodyStr)
82 req, err = http.NewRequest(method, url, reader)
83 contentType = "application/json"
84 }
85
86 if err != nil {
87 return nil, err
88 }
89 if cfg.ORGID != 0 {
90 req.Header.Set(HEADER_KEY_X_ORG_ID, strconv.Itoa(cfg.ORGID))
91 }
92 req.Header.Set("Content-Type", contentType)
93 req.Header.Set("Accept", "application/json, text/plain")
94 req.Header.Set("X-User-Id", "1")
95 req.Header.Set("X-User-Type", "1")
96
97 return parseResponse(req, cfg)
98}
99
100func parseResponse(req *http.Request, cfg *HTTPConf) (*simplejson.Json, error) {
101 errResponse, _ := simplejson.NewJson([]byte("{}"))

Callers 2

GetByFilterFunction · 0.70
GetURLInfoFunction · 0.70

Calls 3

parseResponseFunction · 0.85
SetMethod · 0.65
MarshalMethod · 0.45

Tested by

no test coverage detected