Skip to content

Commit

Permalink
Linter
Browse files Browse the repository at this point in the history
  • Loading branch information
UnicoYal committed Dec 11, 2024
1 parent 22142f4 commit 78cb03e
Show file tree
Hide file tree
Showing 42 changed files with 746 additions and 509 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and Push Docker Images
name: CD

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run Tests with Docker
name: CI

on:
push:
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/linter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Linter

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
linter:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.22.0'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.53
args: --timeout=30m --config=./.golangci.pipeline.yaml --issues-exit-code=0
42 changes: 42 additions & 0 deletions .golangci.pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
run:
concurrency: 8
timeout: 10m
issues-exit-code: 1
tests: true
skip-files:
- \.pb\.go$
- \.pb\.gw\.go$

output:
format: colored-line-number
print-issued-lines: true
print-linter-name: true

linters-settings:
govet:
check-shadowing: true
dupl:
threshold: 100
goconst:
min-len: 2
min-occurrences: 3

linters:
disable-all: true
enable:
- errcheck
- goconst
- goimports
- govet
- ineffassign
- megacheck
- typecheck
- unused

issues:
exclude-use-default: false
exclude:
- G104
- exported func .* returns unexported type .*, which can be annoying to use
- should have a package comment
- don't use an underscore in package name
6 changes: 4 additions & 2 deletions auth_service/internal/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/go-park-mail-ru/2024_2_GOATS/auth_service/internal/interceptors"
auth "github.com/go-park-mail-ru/2024_2_GOATS/auth_service/pkg/auth_v1"
"github.com/go-redis/redis/v8"
"github.com/grpc-ecosystem/go-grpc-prometheus"
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/rs/zerolog"
"google.golang.org/grpc"
Expand Down Expand Up @@ -58,7 +58,9 @@ func New(isTest bool) (*AuthApp, error) {

go func() {
http.Handle("/metrics", promhttp.Handler())
http.ListenAndServe(":9081", nil)
if err := http.ListenAndServe(":9081", nil); err != nil {
logger.Error().Err(err).Msg("Metrics stopped")
}
}()

return &AuthApp{
Expand Down
19 changes: 16 additions & 3 deletions auth_service/internal/auth/repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
)

var expirationTime = time.Now().Add(24 * time.Hour)
var closeRDBError = "cannot_close_redis_db"

func TestAuthRepository_SetCookie(t *testing.T) {
tests := []struct {
Expand Down Expand Up @@ -63,7 +64,11 @@ func TestAuthRepository_SetCookie(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
rdb, mock := redismock.NewClientMock()
defer rdb.Close()
defer func() {
if err := rdb.Close(); err != nil {
t.Errorf("%s:%v", closeRDBError, err)
}
}()

test.mockSetup(mock)
repo := NewAuthRepository(rdb)
Expand Down Expand Up @@ -110,7 +115,11 @@ func TestAuthRepository_DestroySession(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
rdb, mock := redismock.NewClientMock()
defer rdb.Close()
defer func() {
if err := rdb.Close(); err != nil {
t.Errorf("%s:%v", closeRDBError, err)
}
}()

test.mockSetup(mock)
repo := NewAuthRepository(rdb)
Expand Down Expand Up @@ -168,7 +177,11 @@ func TestAuthRepository_GetSessionData(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
rdb, mock := redismock.NewClientMock()
defer rdb.Close()
defer func() {
if err := rdb.Close(); err != nil {
t.Errorf("%s:%v", closeRDBError, err)
}
}()

test.mockSetup(mock)
repo := NewAuthRepository(rdb)
Expand Down
2 changes: 1 addition & 1 deletion auth_service/internal/auth/service/cookie/cookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"fmt"
"time"

"github.com/go-park-mail-ru/2024_2_GOATS/auth_service/internal/auth/service/dto"
"github.com/go-park-mail-ru/2024_2_GOATS/auth_service/config"
"github.com/go-park-mail-ru/2024_2_GOATS/auth_service/internal/auth/service/dto"
"github.com/rs/zerolog/log"
)

Expand Down
3 changes: 2 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package main

import (
"github.com/go-park-mail-ru/2024_2_GOATS/internal/app"
"log"

"github.com/go-park-mail-ru/2024_2_GOATS/internal/app"
)

func main() {
Expand Down
24 changes: 15 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/elastic/go-elasticsearch/v7 v7.17.10
github.com/go-redis/redis/v8 v8.11.5
github.com/go-redis/redismock/v8 v8.11.5
github.com/golang-migrate/migrate v3.5.4+incompatible
github.com/golang/mock v1.6.0
github.com/gorilla/mux v1.8.1
github.com/gorilla/sessions v1.3.0
Expand All @@ -19,9 +20,8 @@ require (
github.com/prometheus/client_golang v1.20.5
github.com/rs/zerolog v1.33.0
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
go.uber.org/mock v0.5.0
golang.org/x/crypto v0.27.0
github.com/stretchr/testify v1.10.0
golang.org/x/crypto v0.29.0
google.golang.org/grpc v1.68.0
google.golang.org/protobuf v1.35.2
)
Expand All @@ -37,10 +37,11 @@ require (
github.com/containerd/continuity v0.4.3 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/docker v27.4.0+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/golang-migrate/migrate v3.5.4+incompatible // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/gorilla/securecookie v1.1.2 // indirect
github.com/gotestyourself/gotestyourself v2.2.0+incompatible // indirect
Expand All @@ -50,16 +51,19 @@ require (
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/onsi/gomega v1.34.2 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/opencontainers/runc v1.1.13 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
Expand All @@ -68,12 +72,14 @@ require (
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
go.opentelemetry.io/otel/trace v1.29.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.20.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit 78cb03e

Please sign in to comment.