Skip to content

Commit

Permalink
gofumpt
Browse files Browse the repository at this point in the history
  • Loading branch information
KshitijaKakde committed May 31, 2024
1 parent 1c282db commit f88395d
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,42 +72,42 @@ type ClientPersistent struct {

// GetVersion returns version
func (c *Client) GetVersion() (string, error) {
resp, err := c.api.DoAndGetResponseBody(
context.Background(), http.MethodGet, "/api/version", nil, nil, c.configConnect.Version)
if err != nil {
return "", err
}
defer func() {
if err := resp.Body.Close(); err != nil {
doLog(log.WithError(err).Error, "")
}
}()
// parse the response
switch {
case resp == nil:
return "", errNilReponse
case resp.StatusCode == http.StatusUnauthorized:
// Authenticate then try again
if _, err = c.Authenticate(c.configConnect); err != nil {
return "", err
}
resp, err = c.api.DoAndGetResponseBody(
context.Background(), http.MethodGet, "/api/version", nil, nil, c.configConnect.Version)
if err != nil {
return "", err
}
case resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusUnauthorized:
return "", c.api.ParseJSONError(resp)
}
version, err := extractString(resp)
if err != nil {
return "", err
}
versionRX := regexp.MustCompile(`^(\d+?\.\d+?).*$`)
if m := versionRX.FindStringSubmatch(version); len(m) > 0 {
return m[1], nil
}
return version, nil
resp, err := c.api.DoAndGetResponseBody(
context.Background(), http.MethodGet, "/api/version", nil, nil, c.configConnect.Version)
if err != nil {
return "", err
}
defer func() {
if err := resp.Body.Close(); err != nil {
doLog(log.WithError(err).Error, "")
}
}()
// parse the response
switch {
case resp == nil:
return "", errNilReponse
case resp.StatusCode == http.StatusUnauthorized:
// Authenticate then try again
if _, err = c.Authenticate(c.configConnect); err != nil {
return "", err
}
resp, err = c.api.DoAndGetResponseBody(
context.Background(), http.MethodGet, "/api/version", nil, nil, c.configConnect.Version)
if err != nil {
return "", err
}
case resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusUnauthorized:
return "", c.api.ParseJSONError(resp)
}
version, err := extractString(resp)
if err != nil {
return "", err
}
versionRX := regexp.MustCompile(`^(\d+?\.\d+?).*$`)
if m := versionRX.FindStringSubmatch(version); len(m) > 0 {
return m[1], nil
}
return version, nil
}

// updateVersion updates version
Expand Down

0 comments on commit f88395d

Please sign in to comment.