Skip to content

Commit

Permalink
Merge pull request #110 from dell/fix-golanci-lint-warnings
Browse files Browse the repository at this point in the history
Fix golagnci lint warnings
  • Loading branch information
alikdell authored Apr 26, 2024
2 parents aab6129 + cdd1e75 commit 9138a73
Show file tree
Hide file tree
Showing 65 changed files with 913 additions and 1,022 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: Workflow
on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]
workflow_dispatch:
jobs:
code-check:
name: Check Go formatting, linting, vetting
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/linters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: [main]
pull_request:
branches: ["**"]
workflow_dispatch:

permissions:
contents: read
Expand All @@ -14,17 +15,17 @@ jobs:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: "1.20"
go-version: "1.22"
cache: false
- name: Checkout the code
uses: actions/checkout@v3.2.0
uses: actions/checkout@v4.1.0
- name: Vendor packages
run: |
go mod vendor
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v4
with:
version: v1.53
version: latest
skip-cache: true
26 changes: 11 additions & 15 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ type Client struct {
}

// Cluster defines struct for Cluster
type Cluster struct {
}
type Cluster struct{}

// ConfigConnect defines struct for ConfigConnect
type ConfigConnect struct {
Expand All @@ -73,7 +72,6 @@ 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 {
Expand Down Expand Up @@ -108,7 +106,6 @@ func (c *Client) GetVersion() (string, error) {

// updateVersion updates version
func (c *Client) updateVersion() error {

version, err := c.GetVersion()
if err != nil {
return err
Expand All @@ -132,7 +129,6 @@ func updateHeaders(version string) {

// Authenticate controls authentication to client
func (c *Client) Authenticate(configConnect *ConfigConnect) (Cluster, error) {

configConnect.Version = c.configConnect.Version
c.configConnect = configConnect

Expand Down Expand Up @@ -187,8 +183,8 @@ func basicAuth(username, password string) string {

func (c *Client) getJSONWithRetry(
method, uri string,
body, resp interface{}) error {

body, resp interface{},
) error {
headers := make(map[string]string, 2)
headers[api.HeaderKeyAccept] = accHeader
headers[api.HeaderKeyContentType] = conHeader
Expand Down Expand Up @@ -240,8 +236,8 @@ func extractString(resp *http.Response) (string, error) {

func (c *Client) getStringWithRetry(
method, uri string,
body interface{}) (string, error) {

body interface{},
) (string, error) {
headers := make(map[string]string, 2)
headers[api.HeaderKeyAccept] = accHeader
headers[api.HeaderKeyContentType] = conHeader
Expand Down Expand Up @@ -333,8 +329,8 @@ func NewClientWithArgs(
version string,
timeout int64,
insecure,
useCerts bool) (client *Client, err error) {

useCerts bool,
) (client *Client, err error) {
if showHTTP {
debug = true
}
Expand Down Expand Up @@ -401,8 +397,8 @@ func withFields(fields map[string]interface{}, message string) error {
}

func withFieldsE(
fields map[string]interface{}, message string, inner error) error {

fields map[string]interface{}, message string, inner error,
) error {
if fields == nil {
fields = make(map[string]interface{})
}
Expand All @@ -429,8 +425,8 @@ func withFieldsE(

func doLog(
l func(args ...interface{}),
msg string) {

msg string,
) {
if debug {
l(msg)
}
Expand Down
43 changes: 20 additions & 23 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ var (

// Client is an API client.
type Client interface {

// Do sends an HTTP request to the API.
Do(
ctx context.Context,
Expand Down Expand Up @@ -136,11 +135,11 @@ type ClientOptions struct {

// New returns a new API client.
func New(
ctx context.Context,
_ context.Context,
host string,
opts ClientOptions,
debug bool) (Client, error) {

debug bool,
) (Client, error) {
if host == "" {
return nil, errNewClient
}
Expand Down Expand Up @@ -193,8 +192,8 @@ func (c *client) Get(
ctx context.Context,
path string,
headers map[string]string,
resp interface{}) error {

resp interface{},
) error {
return c.DoWithHeaders(
ctx, http.MethodGet, path, headers, nil, resp, "")
}
Expand All @@ -203,8 +202,8 @@ func (c *client) Post(
ctx context.Context,
path string,
headers map[string]string,
body, resp interface{}) error {

body, resp interface{},
) error {
return c.DoWithHeaders(
ctx, http.MethodPost, path, headers, body, resp, "")
}
Expand All @@ -213,8 +212,8 @@ func (c *client) Put(
ctx context.Context,
path string,
headers map[string]string,
body, resp interface{}) error {

body, resp interface{},
) error {
return c.DoWithHeaders(
ctx, http.MethodPut, path, headers, body, resp, "")
}
Expand All @@ -223,17 +222,17 @@ func (c *client) Delete(
ctx context.Context,
path string,
headers map[string]string,
resp interface{}) error {

resp interface{},
) error {
return c.DoWithHeaders(
ctx, http.MethodDelete, path, headers, nil, resp, "")
}

func (c *client) Do(
ctx context.Context,
method, path string,
body, resp interface{}) error {

body, resp interface{},
) error {
return c.DoWithHeaders(ctx, method, path, nil, body, resp, "")
}

Expand All @@ -249,8 +248,8 @@ func (c *client) DoWithHeaders(
ctx context.Context,
method, uri string,
headers map[string]string,
body, resp interface{}, version string) error {

body, resp interface{}, version string,
) error {
res, err := c.DoAndGetResponseBody(
ctx, method, uri, headers, body, version)
if err != nil {
Expand Down Expand Up @@ -289,8 +288,8 @@ func (c *client) DoAndGetResponseBody(
ctx context.Context,
method, uri string,
headers map[string]string,
body interface{}, version string) (*http.Response, error) {

body interface{}, version string,
) (*http.Response, error) {
var (
err error
req *http.Request
Expand Down Expand Up @@ -388,7 +387,6 @@ func (c *client) DoAndGetResponseBody(
} else {
req.SetBasicAuth("", c.token)
}

}

} else {
Expand Down Expand Up @@ -423,10 +421,9 @@ func (c *client) GetToken() string {
}

func (c *client) ParseJSONError(r *http.Response) error {

jsonError := &types.Error{}

//Starting in 4.0, response may be in html; so we cannot always use a json decoder
// Starting in 4.0, response may be in html; so we cannot always use a json decoder
if strings.Contains(r.Header.Get("Content-Type"), "html") {
jsonError.HTTPStatusCode = r.StatusCode
jsonError.Message = r.Status
Expand All @@ -447,8 +444,8 @@ func (c *client) ParseJSONError(r *http.Response) error {

func (c *client) doLog(
l func(args ...interface{}),
msg string) {

msg string,
) {
if c.debug {
l(msg)
}
Expand Down
13 changes: 6 additions & 7 deletions api/api_logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ func isBinOctetBody(h http.Header) bool {
}

func logRequest(
ctx context.Context,
_ context.Context,
req *http.Request,
lf func(func(args ...interface{}), string)) {

lf func(func(args ...interface{}), string),
) {
log.SetLevel(log.DebugLevel)

w := &bytes.Buffer{}
Expand All @@ -44,7 +44,6 @@ func logRequest(
fmt.Fprintln(w, " -------------------------")

buf, err := dumpRequest(req, !isBinOctetBody(req.Header))

if err != nil {
return
}
Expand All @@ -59,10 +58,10 @@ func logRequest(
}

func logResponse(
ctx context.Context,
_ context.Context,
res *http.Response,
lf func(func(args ...interface{}), string)) {

_ func(func(args ...interface{}), string),
) {
log.SetLevel(log.DebugLevel)

w := &bytes.Buffer{}
Expand Down
5 changes: 2 additions & 3 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ func TestClientLogin(t *testing.T) {
default:
t.Fatal("Expecting endpoint /api/login got", req.RequestURI)
}

},
))
defer server.Close()
Expand Down Expand Up @@ -167,7 +166,7 @@ func (s stubTypeWithMetaData) MetaData() http.Header {
}

func Test_addMetaData(t *testing.T) {
var tests = []struct {
tests := []struct {
name string
givenHeader map[string]string
expectedHeader map[string]string
Expand Down Expand Up @@ -201,7 +200,7 @@ func Test_addMetaData(t *testing.T) {
}
}

func Test_updateHeaders(t *testing.T) {
func Test_updateHeaders(_ *testing.T) {
var wg sync.WaitGroup
for i := 0; i < 3; i++ {
wg.Add(1)
Expand Down
Loading

0 comments on commit 9138a73

Please sign in to comment.