Add delete
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
2022-01-21 07:17:52 +01:00
parent ff8c6aca64
commit ed4a10c966
5 changed files with 101 additions and 0 deletions

View File

@@ -203,3 +203,24 @@ func (c *Client) Upload(ctx context.Context, files ...*files.File) ([]api.Respon
return expectedResp, nil
}
func (c *Client) Delete(ctx context.Context, id string) error {
url := fmt.Sprintf("%s/api/file/%s", c.BaseURL, id)
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, url, nil)
if err != nil {
return fmt.Errorf("error creating request: %w", err)
}
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", c.AuthToken))
resp, err := c.httpClient.Do(req)
if err != nil {
return fmt.Errorf("unable to perform request: %s", err)
}
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("got non-ok response from server: %s", resp.Status)
}
return nil
}