Skip to content
Snippets Groups Projects
Commit 8be90307 authored by ale's avatar ale
Browse files

Pass a Context do DoJSONHTTPRequest

parent 41657e75
Branches
Tags
No related merge requests found
......@@ -2,13 +2,17 @@ package clientutil
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
)
func DoJSONHTTPRequest(client *http.Client, uri string, req, resp interface{}) error {
// DoJSONHTTPRequest makes an HTTP POST request to the specified uri,
// with a JSON-encoded request body. It will attempt to decode the
// response body as JSON.
func DoJSONHTTPRequest(ctx context.Context, client *http.Client, uri string, req, resp interface{}) error {
data, err := json.Marshal(req)
if err != nil {
return err
......@@ -19,6 +23,7 @@ func DoJSONHTTPRequest(client *http.Client, uri string, req, resp interface{}) e
return err
}
httpReq.Header.Set("Content-Type", "application/json")
httpReq = httpReq.WithContext(ctx)
httpResp, err := RetryHTTPDo(client, httpReq, NewExponentialBackOff())
if err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment