MCPcopy
hub / github.com/dgraph-io/dgraph / runRequest

Function runRequest

dgraph/cmd/alpha/http_test.go:288–311  ·  view source on GitHub ↗

attach the grootAccessJWT to the request and sends the http request

(req *http.Request)

Source from the content-addressed store, hash-verified

286
287// attach the grootAccessJWT to the request and sends the http request
288func runRequest(req *http.Request) (*x.QueryResWithData, []byte, *http.Response, error) {
289 client := &http.Client{}
290 req.Header.Set("X-Dgraph-AccessToken", token.getAccessJWTToken())
291 resp, err := client.Do(req)
292 if err != nil {
293 return nil, nil, resp, err
294 }
295 if status := resp.StatusCode; status != http.StatusOK {
296 return nil, nil, resp, errors.Errorf("Unexpected status code: %v", status)
297 }
298
299 defer resp.Body.Close()
300 body, err := io.ReadAll(resp.Body)
301 if err != nil {
302 return nil, nil, resp, errors.Errorf("unable to read from body: %v", err)
303 }
304
305 qr := new(x.QueryResWithData)
306 _ = json.Unmarshal(body, qr) // Don't check error.
307 if len(qr.Errors) > 0 {
308 return nil, nil, resp, errors.New(qr.Errors[0].Message)
309 }
310 return qr, body, resp, nil
311}
312
313func runWithRetriesForResp(method, contentType, url string, body string) (
314 *x.QueryResWithData, []byte, *http.Response, error) {

Callers 6

fetchMetricsFunction · 0.85
TestMetricsFunction · 0.85
runWithRetriesForRespFunction · 0.85
commitWithTsFunction · 0.85
commitWithTsKeysOnlyFunction · 0.85

Calls 4

getAccessJWTTokenMethod · 0.80
SetMethod · 0.65
CloseMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected