MCPcopy
hub / github.com/prometheus/client_golang / Do

Method Do

api/client.go:129–156  ·  view source on GitHub ↗
(ctx context.Context, req *http.Request)

Source from the content-addressed store, hash-verified

127}
128
129func (c *httpClient) Do(ctx context.Context, req *http.Request) (*http.Response, []byte, error) {
130 if ctx != nil {
131 req = req.WithContext(ctx)
132 }
133 resp, err := c.client.Do(req)
134 if err != nil {
135 return nil, nil, err
136 }
137
138 var body []byte
139 done := make(chan error, 1)
140 go func() {
141 var buf bytes.Buffer
142 _, err := buf.ReadFrom(resp.Body)
143 body = buf.Bytes()
144 done <- err
145 }()
146
147 select {
148 case <-ctx.Done():
149 resp.Body.Close()
150 <-done
151 return resp, nil, ctx.Err()
152 case err = <-done:
153 resp.Body.Close()
154 return resp, body, err
155 }
156}

Callers

nothing calls this directly

Calls 3

ErrMethod · 0.80
DoMethod · 0.65
ReadFromMethod · 0.45

Tested by

no test coverage detected