File tree Expand file tree Collapse file tree 1 file changed +0
-37
lines changed
Expand file tree Collapse file tree 1 file changed +0
-37
lines changed Original file line number Diff line number Diff line change 11package paperswithcode_go
22
33import (
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- }
You can’t perform that action at this time.
0 commit comments