MCPcopy Create free account
hub / github.com/LagrangeDev/LagrangeGo / httpGet

Function httpGet

client/sign/http.go:74–99  ·  view source on GitHub ↗
(rawURL string, queryParams map[string]string, timeout time.Duration, header http.Header)

Source from the content-addressed store, hash-verified

72}
73
74func httpGet[T any](rawURL string, queryParams map[string]string, timeout time.Duration, header http.Header) (target T, err error) {
75 u, err := url.Parse(rawURL)
76 if err != nil {
77 return
78 }
79
80 q := u.Query()
81 for k, v := range queryParams {
82 q.Set(k, v)
83 }
84 u.RawQuery = q.Encode()
85
86 ctx, cancel := context.WithTimeout(context.Background(), timeout)
87 defer cancel()
88
89 req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil)
90 if err != nil {
91 return
92 }
93 for k, vs := range header {
94 for _, v := range vs {
95 req.Header.Add(k, v)
96 }
97 }
98 return doHTTP[T](ctx, req)
99}
100
101func httpPost[T any](rawURL string, body io.Reader, timeout time.Duration, header http.Header) (target T, err error) {
102 u, err := url.Parse(rawURL)

Callers

nothing calls this directly

Calls 2

EncodeMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected