Skip to content

Commit

Permalink
fix: DELETE eof
Browse files Browse the repository at this point in the history
  • Loading branch information
CorentinB committed Nov 6, 2024
1 parent b6a2f75 commit ccdf90d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
19 changes: 6 additions & 13 deletions delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import (
"net/http"
)

func (c *Client) Delete(URLs []URL, localCrawls int) (finishedResponse *DeleteResponse, err error) {
func (c *Client) Delete(URLs []URL, localCrawls int) (err error) {
expectedStatusCode := 204
finishedResponse = new(DeleteResponse)

// build payload
payload := DeletePayload{
Expand All @@ -19,13 +18,13 @@ func (c *Client) Delete(URLs []URL, localCrawls int) (finishedResponse *DeleteRe

jsonPayload, err := json.Marshal(payload)
if err != nil {
return finishedResponse, err
return err
}

// build request
req, err := http.NewRequest("DELETE", c.URLsEndpoint.String(), bytes.NewReader(jsonPayload))
if err != nil {
return finishedResponse, err
return err
}

req.Header.Add("X-Auth-Key", c.Key)
Expand All @@ -39,20 +38,14 @@ func (c *Client) Delete(URLs []URL, localCrawls int) (finishedResponse *DeleteRe
// execute request
resp, err := c.HTTPClient.Do(req)
if err != nil {
return finishedResponse, err
return err
}
defer resp.Body.Close()

// check response status code
if resp.StatusCode != expectedStatusCode {
return finishedResponse, fmt.Errorf("non-%d status code: %d", expectedStatusCode, resp.StatusCode)
return fmt.Errorf("non-%d status code: %d", expectedStatusCode, resp.StatusCode)
}

// decode response body
err = json.NewDecoder(resp.Body).Decode(finishedResponse)
if err != nil {
return finishedResponse, err
}

return finishedResponse, err
return err
}
4 changes: 0 additions & 4 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ type GetResponse struct {
URLs []URL `json:"urls"`
}

type DeleteResponse struct {
Project string `json:"project"`
}

type AddPayload struct {
URLs []URL `json:"urls"`
BypassSeencheck bool `json:"bypassSeencheck"`
Expand Down

0 comments on commit ccdf90d

Please sign in to comment.