MCPcopy Index your code
hub / github.com/APIParkLab/APIPark / SendRequest

Function SendRequest

login_driver/feishu/client.go:19–56  ·  view source on GitHub ↗
(uri string, method string, header http.Header, query url.Values, body []byte)

Source from the content-addressed store, hash-verified

17)
18
19func SendRequest[T any](uri string, method string, header http.Header, query url.Values, body []byte) (*T, error) {
20 if uri == "" {
21 return nil, fmt.Errorf("invalid URL")
22 }
23
24 req, err := http.NewRequest(method, uri, bytes.NewReader(body))
25 if err != nil {
26 return nil, err
27 }
28
29 if query != nil {
30 req.URL.RawQuery = query.Encode()
31 }
32
33 if header != nil {
34 req.Header = header
35 }
36
37 resp, err := client.Do(req)
38 if err != nil {
39 return nil, err
40 }
41 defer resp.Body.Close()
42 respBody, err := io.ReadAll(resp.Body)
43 if err != nil {
44 return nil, err
45 }
46 result := new(T)
47 err = json.Unmarshal(respBody, result)
48 if err != nil {
49 return nil, err
50 }
51 if resp.StatusCode != http.StatusOK {
52 return nil, fmt.Errorf("status code error: %d, response: %s", resp.StatusCode, respBody)
53 }
54
55 return result, nil
56}

Callers

nothing calls this directly

Calls 2

EncodeMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected