Skip to content

Commit f238108

Browse files
authored
Merge pull request #9 from codingpot/refactor-5-remove-send-request-function
refactor: remove sendRequest function
2 parents d3879fb + 63608c9 commit f238108

File tree

1 file changed

+0
-37
lines changed

1 file changed

+0
-37
lines changed

client.go

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package paperswithcode_go
22

33
import (
4-
"encoding/json"
5-
"errors"
6-
"fmt"
74
"github.com/codingpot/paperswithcode-go/internal/transport"
85
"net/http"
96
"time"
@@ -45,37 +42,3 @@ type Client struct {
4542
HTTPClient *http.Client
4643
apiToken string
4744
}
48-
49-
type errorResponse struct {
50-
Code int `json:"code"`
51-
Message string `json:"message"`
52-
}
53-
54-
func (c *Client) sendRequest(req *http.Request, v interface{}) error {
55-
req.Header.Set("Content-Type", "application/json; charset=utf-8")
56-
req.Header.Set("Accept", "application/json; charset=utf-8")
57-
58-
res, err := c.HTTPClient.Do(req)
59-
if err != nil {
60-
return err
61-
}
62-
63-
defer res.Body.Close()
64-
65-
if res.StatusCode < http.StatusOK || res.StatusCode >= http.StatusBadRequest {
66-
var errRes errorResponse
67-
if err = json.NewDecoder(res.Body).Decode(&errRes); err == nil {
68-
return errors.New(errRes.Message)
69-
}
70-
71-
return fmt.Errorf("unknown error, status code: %d", res.StatusCode)
72-
}
73-
74-
if err = json.NewDecoder(res.Body).Decode(&v); err != nil {
75-
return err
76-
}
77-
78-
// fmt.Println(fullResponse)
79-
80-
return nil
81-
}

0 commit comments

Comments
 (0)