Skip to content

Commit

Permalink
chore: add linter (bxcodec#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
bxcodec authored Apr 18, 2020
1 parent c8b6b9b commit 0e2d18a
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 16 deletions.
80 changes: 80 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
govet:
check-shadowing: true
settings:
printf:
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
golint:
min-confidence: 0.8
gocyclo:
min-complexity: 20
maligned:
suggest-new: true
dupl:
threshold: 100
goconst:
min-len: 2
min-occurrences: 5
misspell:
locale: US
lll:
line-length: 160
# tab width in spaces. Default to 1.
tab-width: 1
funlen:
lines: 120
statements: 50

linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- deadcode
- errcheck
- funlen
- goconst
# - gocritic
- gocyclo
- golint
- gosec
- gosimple
- govet
- ineffassign
- interfacer
- lll
- misspell
- staticcheck
- structcheck
- typecheck
- unconvert
- unparam
- unused
- varcheck

run:
# default concurrency is a available CPU number
concurrency: 2

skip-dirs:
# - test/testdata_etc
skip-files:
# - .*_test.go

issues:
exclude-rules:
- path: internal/(cache|renameio)/
linters:
- lll
- gochecknoinits
- gocyclo
- funlen
- path: .*_test.go
linters:
- funlen
exclude-use-default: false
exclude:
- should have a package comment
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Builder
FROM golang:1.12.8-alpine3.10 as builder
FROM golang:1.14.2-alpine3.11 as builder

RUN apk update && apk upgrade && \
apk --update add git make
Expand Down
10 changes: 2 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ docker:
docker build -t go-clean-arch .

run:
docker-compose up -d
docker-compose up --build -d

stop:
docker-compose down
Expand All @@ -25,12 +25,6 @@ lint-prepare:
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s latest

lint:
./bin/golangci-lint run \
--exclude-use-default=false \
--enable=golint \
--enable=gocyclo \
--enable=goconst \
--enable=unconvert \
./...
./bin/golangci-lint run ./...

.PHONY: clean install unittest build docker run stop vendor lint-prepare lint
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/bxcodec/go-clean-arch/middleware"
"github.com/bxcodec/go-clean-arch/article/delivery/http/middleware"
)

func TestCORS(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
version: "2.3"
services:
web:
image: go-clean-arch
build:
context: .
dockerfile: Dockerfile
container_name: article_management_api
ports:
- 9090:9090
Expand Down
9 changes: 4 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ import (
"fmt"
"log"
"net/url"
"os"
"time"

_ "github.com/go-sql-driver/mysql"
"github.com/labstack/echo"
"github.com/spf13/viper"

_articleHttpDeliver "github.com/bxcodec/go-clean-arch/article/delivery/http"
_articleHttpDelivery "github.com/bxcodec/go-clean-arch/article/delivery/http"
_articleHttpDeliveryMiddleware "github.com/bxcodec/go-clean-arch/article/delivery/http/middleware"
_articleRepo "github.com/bxcodec/go-clean-arch/article/repository"
_articleUcase "github.com/bxcodec/go-clean-arch/article/usecase"
_authorRepo "github.com/bxcodec/go-clean-arch/author/repository"
"github.com/bxcodec/go-clean-arch/middleware"
)

func init() {
Expand Down Expand Up @@ -59,14 +58,14 @@ func main() {
}()

e := echo.New()
middL := middleware.InitMiddleware()
middL := _articleHttpDeliveryMiddleware.InitMiddleware()
e.Use(middL.CORS)
authorRepo := _authorRepo.NewMysqlAuthorRepository(dbConn)
ar := _articleRepo.NewMysqlArticleRepository(dbConn)

timeoutContext := time.Duration(viper.GetInt("context.timeout")) * time.Second
au := _articleUcase.NewArticleUsecase(ar, authorRepo, timeoutContext)
_articleHttpDeliver.NewArticleHandler(e, au)
_articleHttpDelivery.NewArticleHandler(e, au)

log.Fatal(e.Start(viper.GetString("server.address")))
}

0 comments on commit 0e2d18a

Please sign in to comment.