Skip to content

Commit

Permalink
Linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaspence committed Nov 21, 2024
1 parent c868476 commit a6eab9f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 22 deletions.
16 changes: 4 additions & 12 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ linters:
# Temporary
- 'cyclop'
- 'dupl'
- 'err113'
- 'exhaustruct'
- 'forbidigo'
- 'funlen'
Expand All @@ -17,28 +18,19 @@ linters:
- 'gocritic'
- 'gocyclo'
- 'godox'
- 'goerr113'
- 'gomnd'
- 'gosec'
- 'lll'
- 'maintidx'
- 'mnd'
- 'nestif'
- 'nlreturn'
- 'paralleltest'
- 'perfsprint'
- 'revive'
- 'stylecheck'
- 'varnamelen'
- 'wrapcheck'
- 'wsl'

# Deprecated
- 'deadcode'
- 'exhaustivestruct'
- 'golint'
- 'ifshort'
- 'interfacer'
- 'maligned'
- 'nosnakecase'
- 'scopelint'
- 'structcheck'
- 'varcheck'
- 'exportloopref'
2 changes: 1 addition & 1 deletion fields/fwupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type firmwareUpdateApiResponseEmbeddedFirmwareDataLink struct {
Href *url.URL `json:"href"`
}

func (l firmwareUpdateApiResponseEmbeddedFirmwareDataLink) MarshalJSON() ([]byte, error) {
func (l *firmwareUpdateApiResponseEmbeddedFirmwareDataLink) MarshalJSON() ([]byte, error) {
var href string
if l.Href != nil {
href = l.Href.String()
Expand Down
2 changes: 1 addition & 1 deletion fields/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func TestResourceTypes(t *testing.T) {

err := resource.processJSON(([]byte)(testData))

assert.Empty(t, err, "No error processing JSON")
assert.NoError(t, err, "No error processing JSON")

Check failure on line 154 in fields/main_test.go

View workflow job for this annotation

GitHub Actions / lint

require-error: for error assertions use require (testifylint)
assert.Equal(t, expectation.StructName, resource.StructName)
assert.Equal(t, expectation.ResourcePath, resource.ResourcePath)
assert.Equal(t, expectation.Types, resource.Types)
Expand Down
4 changes: 2 additions & 2 deletions fields/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ func TestLatestUnifiVersion(t *testing.T) {
assert.Contains(query["filter"], firmwareUpdateApiFilter("product", unifiControllerProduct))

resp, err := json.Marshal(respData)
require.NoError(err)
assert.NoError(err)

_, err = rw.Write(resp)
require.NoError(err)
assert.NoError(err)
}))
defer server.Close()

Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module github.com/paultyng/go-unifi

go 1.22
go 1.22.1

toolchain go1.23.1

require (
Expand Down
9 changes: 4 additions & 5 deletions unifi/unifi.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/cookiejar"
"net/url"
Expand Down Expand Up @@ -114,7 +113,7 @@ func (c *Client) setAPIUrlStyle(ctx context.Context) error {
return err
}
defer resp.Body.Close()
_, _ = io.Copy(ioutil.Discard, resp.Body)
_, _ = io.Copy(io.Discard, resp.Body)

if resp.StatusCode == http.StatusOK {
// the new API returns a 200 for a / request
Expand Down Expand Up @@ -226,7 +225,7 @@ func (c *Client) do(ctx context.Context, method, relativeURL string, reqBody int
req.Header.Add("Content-Type", "application/json; charset=utf-8")

if c.csrf != "" {
req.Header.Set("X-CSRF-Token", c.csrf)
req.Header.Set("X-Csrf-Token", c.csrf)
}

resp, err := c.c.Do(req)
Expand All @@ -239,8 +238,8 @@ func (c *Client) do(ctx context.Context, method, relativeURL string, reqBody int
return &NotFoundError{}
}

if csrf := resp.Header.Get("x-csrf-token"); csrf != "" {
c.csrf = resp.Header.Get("x-csrf-token")
if csrf := resp.Header.Get("X-Csrf-Token"); csrf != "" {
c.csrf = resp.Header.Get("X-Csrf-Token")
}

if resp.StatusCode != http.StatusOK {
Expand Down

0 comments on commit a6eab9f

Please sign in to comment.