MCPcopy Index your code
hub / github.com/golang/groupcache / Get

Method Get

http.go:195–231  ·  view source on GitHub ↗
(ctx context.Context, in *pb.GetRequest, out *pb.GetResponse)

Source from the content-addressed store, hash-verified

193}
194
195func (h *httpGetter) Get(ctx context.Context, in *pb.GetRequest, out *pb.GetResponse) error {
196 u := fmt.Sprintf(
197 "%v%v/%v",
198 h.baseURL,
199 url.QueryEscape(in.GetGroup()),
200 url.QueryEscape(in.GetKey()),
201 )
202 req, err := http.NewRequest("GET", u, nil)
203 if err != nil {
204 return err
205 }
206 req = req.WithContext(ctx)
207 tr := http.DefaultTransport
208 if h.transport != nil {
209 tr = h.transport(ctx)
210 }
211 res, err := tr.RoundTrip(req)
212 if err != nil {
213 return err
214 }
215 defer res.Body.Close()
216 if res.StatusCode != http.StatusOK {
217 return fmt.Errorf("server returned: %v", res.Status)
218 }
219 b := bufferPool.Get().(*bytes.Buffer)
220 b.Reset()
221 defer bufferPool.Put(b)
222 _, err = io.Copy(b, res.Body)
223 if err != nil {
224 return fmt.Errorf("reading response body: %v", err)
225 }
226 err = proto.Unmarshal(b.Bytes(), out)
227 if err != nil {
228 return fmt.Errorf("decoding response body: %v", err)
229 }
230 return nil
231}

Callers

nothing calls this directly

Calls 5

GetGroupMethod · 0.80
GetKeyMethod · 0.80
CopyMethod · 0.80
GetMethod · 0.65
ResetMethod · 0.45

Tested by

no test coverage detected