|
|
@ -305,6 +305,38 @@ func (c *Client) legacyPost(ctx context.Context, resource string, body interface |
|
|
|
return json.NewDecoder(res.Body).Decode(target) |
|
|
|
} |
|
|
|
|
|
|
|
func (c *Client) legacyDelete(ctx context.Context, resource string, target interface{}) error { |
|
|
|
select { |
|
|
|
case <-ctx.Done(): |
|
|
|
return ctx.Err() |
|
|
|
case <-c.ch: |
|
|
|
defer func() { |
|
|
|
c.ch <- struct{}{} |
|
|
|
}() |
|
|
|
} |
|
|
|
|
|
|
|
if c.token != "" { |
|
|
|
resource = c.token + "/" + resource |
|
|
|
} |
|
|
|
|
|
|
|
req, err := http.NewRequest("DELETE", fmt.Sprintf("http://%s/api/%s", c.host, resource), nil) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
res, err := httpClient.Do(req.WithContext(ctx)) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
defer res.Body.Close() |
|
|
|
|
|
|
|
if target == nil { |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
return json.NewDecoder(res.Body).Decode(target) |
|
|
|
} |
|
|
|
|
|
|
|
func reqBody(body interface{}) (io.Reader, error) { |
|
|
|
if body == nil { |
|
|
|
return nil, nil |
|
|
|