8 const versionPrefix = "/v1"
10 func newRequest(method, host, path string, body io.Reader) (*http.Request, error) {
11 url := "https://" + host + versionPrefix + path
12 req, err := http.NewRequest(method, url, body)
19 case http.MethodDelete:
20 req.Header.Set("Accept", "application/json")
21 case http.MethodPost, http.MethodPut:
22 req.Header.Set("Accept", "application/json")
23 req.Header.Set("Content-Type", "application/json")
25 return nil, fmt.Errorf("new request: unsupported method %s", req.Method)
30 func (c *Client) get(path string) (*http.Response, error) {
31 req, err := newRequest(http.MethodGet, c.host, path, nil)
38 func (c *Client) post(path string, body io.Reader) (*http.Response, error) {
39 req, err := newRequest(http.MethodPost, c.host, path, body)
46 func (c *Client) put(path string, body io.Reader) (*http.Response, error) {
47 req, err := newRequest(http.MethodPut, c.host, path, body)
54 func (c *Client) delete(path string, body io.Reader) (*http.Response, error) {
55 req, err := newRequest(http.MethodDelete, c.host, path, nil)
62 func (c *Client) do(req *http.Request) (*http.Response, error) {
63 req.SetBasicAuth(c.username, c.password)