From 2a82ab0dc01498825b6231f8cd1ddc444c6b031a Mon Sep 17 00:00:00 2001 From: K8sCat Date: Sun, 25 Sep 2022 02:33:24 +0800 Subject: [PATCH] update: remove unreachable code Signed-off-by: K8sCat --- pkg/hub/client.go | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/pkg/hub/client.go b/pkg/hub/client.go index dfe71f2..c9e043f 100644 --- a/pkg/hub/client.go +++ b/pkg/hub/client.go @@ -43,7 +43,7 @@ const ( itemsPerPage = 100 ) -//Client sends authenticated calls to the Hub API +// Client sends authenticated calls to the Hub API type Client struct { AuthConfig types.AuthConfig Ctx context.Context @@ -75,13 +75,13 @@ type tokenResponse struct { RefreshToken string `json:"refresh_token"` } -//ClientOp represents an option given to NewClient constructor to customize client behavior. +// ClientOp represents an option given to NewClient constructor to customize client behavior. type ClientOp func(*Client) error -//RequestOp represents an option to customize the request sent to the Hub API +// RequestOp represents an option to customize the request sent to the Hub API type RequestOp func(r *http.Request) error -//NewClient logs the user to the hub and returns a client which can send authenticated requests +// NewClient logs the user to the hub and returns a client which can send authenticated requests // to the Hub API func NewClient(ops ...ClientOp) (*Client, error) { hubInstance := getInstance() @@ -99,7 +99,7 @@ func NewClient(ops ...ClientOp) (*Client, error) { return client, nil } -//Update changes client behavior using ClientOp +// Update changes client behavior using ClientOp func (c *Client) Update(ops ...ClientOp) error { for _, op := range ops { if err := op(c); err != nil { @@ -109,7 +109,7 @@ func (c *Client) Update(ops ...ClientOp) error { return nil } -//WithAllElements makes the client fetch all the elements it can find, enabling pagination. +// WithAllElements makes the client fetch all the elements it can find, enabling pagination. func WithAllElements() ClientOp { return func(c *Client) error { c.fetchAllElements = true @@ -117,7 +117,7 @@ func WithAllElements() ClientOp { } } -//WithContext set the client context +// WithContext set the client context func WithContext(ctx context.Context) ClientOp { return func(c *Client) error { c.Ctx = ctx @@ -125,7 +125,7 @@ func WithContext(ctx context.Context) ClientOp { } } -//WithInStream sets the input stream +// WithInStream sets the input stream func WithInStream(in io.Reader) ClientOp { return func(c *Client) error { c.in = in @@ -133,7 +133,7 @@ func WithInStream(in io.Reader) ClientOp { } } -//WithOutStream sets the output stream +// WithOutStream sets the output stream func WithOutStream(out io.Writer) ClientOp { return func(c *Client) error { c.out = out @@ -189,7 +189,7 @@ func withHubToken(token string) RequestOp { } } -//WithSortingOrder adds a sorting order query parameter to the request +// WithSortingOrder adds a sorting order query parameter to the request func WithSortingOrder(order string) RequestOp { return func(req *http.Request) error { values, err := url.ParseQuery(req.URL.RawQuery) @@ -326,17 +326,13 @@ func (c *Client) doRequest(req *http.Request, reqOps ...RequestOp) ([]byte, erro return nil, err } } - return nil, fmt.Errorf("bad status code %q", resp.Status) + return nil, fmt.Errorf("bad status code %q: %s", resp.Status, buf) } buf, err := ioutil.ReadAll(resp.Body) log.Tracef("HTTP response body: %s", buf) if err != nil { return nil, err } - if resp.StatusCode < 200 || resp.StatusCode >= 300 { - return nil, fmt.Errorf("bad status code %q: %s", resp.Status, string(buf)) - } - return buf, nil }