Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update: remove unreachable code #211

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions pkg/hub/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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 {
Expand All @@ -109,31 +109,31 @@ 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
return nil
}
}

//WithContext set the client context
// WithContext set the client context
func WithContext(ctx context.Context) ClientOp {
return func(c *Client) error {
c.Ctx = ctx
return nil
}
}

//WithInStream sets the input stream
// WithInStream sets the input stream
func WithInStream(in io.Reader) ClientOp {
return func(c *Client) error {
c.in = in
return nil
}
}

//WithOutStream sets the output stream
// WithOutStream sets the output stream
func WithOutStream(out io.Writer) ClientOp {
return func(c *Client) error {
c.out = out
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down