Skip to content

Commit

Permalink
bump golangci-lint, fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
paskal committed Apr 1, 2023
1 parent 095c080 commit 7d080e5
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 17 deletions.
37 changes: 24 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: set up go 1.18
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: "1.18"
id: go

- name: launch mongodb
Expand All @@ -30,27 +30,38 @@ jobs:
- name: checkout
uses: actions/checkout@v3

- name: build and test
- name: build the example
working-directory: _example
run: |
go get -v
go test -timeout=60s -v -race -p 1 -covermode=atomic -coverprofile=$GITHUB_WORKSPACE/profile.cov_tmp
cat $GITHUB_WORKSPACE/profile.cov_tmp | grep -v "_mock.go" > $GITHUB_WORKSPACE/profile.cov
go build -race
env:
TZ: "America/Chicago"
ENABLE_MONGO_TESTS: "true"

- name: install golangci-lint and goveralls

- name: build and test
run: |
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $GITHUB_WORKSPACE v1.50.1
go install github.com/mattn/goveralls@latest
go test -timeout=60s -v -race -p 1 -covermode=atomic -coverprofile=$GITHUB_WORKSPACE/profile.cov
go build -race
env:
TZ: "America/Chicago"
ENABLE_MONGO_TESTS: "true"

- name: run linters
run: $GITHUB_WORKSPACE/golangci-lint run ./...
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest

- name: run linters on example directory
working-directory: _example
run: $GITHUB_WORKSPACE/golangci-lint --config ../.golangci.yml run ./...
- name: golangci-lint on example directory
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --config ../.golangci.yml
working-directory: _example

- name: install goveralls
run: |
go install github.com/mattn/goveralls@latest
- name: submit coverage
run: goveralls -service="github" -coverprofile=$GITHUB_WORKSPACE/profile.cov
Expand Down
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,9 @@ issues:
text: "Potential Slowloris Attack because ReadHeaderTimeout is not configured in the http.Server"
linters:
- gosec
- path: _test\.go
text: "Deferring unsafe method \"Close\" on type \"io.ReadCloser\""
linters:
- gosec

exclude-use-default: false
2 changes: 1 addition & 1 deletion avatar/avatar.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func GetGravatarURL(email string) (res string, err error) {
if err != nil {
return "", err
}
defer resp.Body.Close()
defer resp.Body.Close() //nolint gosec // we don't care about response body
if resp.StatusCode != 200 {
return "", fmt.Errorf("%s", resp.Status)
}
Expand Down
4 changes: 2 additions & 2 deletions middleware/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func TestAuthJWTRefreshFailed(t *testing.T) {
require.Nil(t, err)
resp, err := client.Do(req)
require.NoError(t, err)
defer resp.Body.Close()
defer resp.Body.Close() //nolint gosec // we don't care about response body
assert.Equal(t, 401, resp.StatusCode)

data, err := io.ReadAll(resp.Body)
Expand Down Expand Up @@ -458,7 +458,7 @@ func TestRBAC(t *testing.T) {
req.Header.Add("X-XSRF-TOKEN", "random id")
resp, err = client.Do(req)
require.NoError(t, err)
defer resp.Body.Close()
defer resp.Body.Close() //nolint gosec // we don't care about response body
assert.Equal(t, 403, resp.StatusCode)

data, err := io.ReadAll(resp.Body)
Expand Down
2 changes: 1 addition & 1 deletion provider/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ func (tg *tgAPI) request(ctx context.Context, method string, data interface{}) e
if err != nil {
return fmt.Errorf("failed to send request: %w", err)
}
defer resp.Body.Close()
defer resp.Body.Close() //nolint gosec // we don't care about response body

if resp.StatusCode != http.StatusOK {
return tg.parseError(resp.Body, resp.StatusCode)
Expand Down

0 comments on commit 7d080e5

Please sign in to comment.