Skip to content

Commit a13edee

Browse files
authored
Merge pull request #7 from jiaozifs/feat/golangci_lint
feat: add golangci lint
2 parents d182dcd + 3615682 commit a13edee

File tree

19 files changed

+161
-65
lines changed

19 files changed

+161
-65
lines changed

.github/workflows/basic_check.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: basic-check
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- '**'
10+
11+
jobs:
12+
check:
13+
runs-on: ubuntu-22.04
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Set up Go
18+
uses: actions/setup-go@v4
19+
with:
20+
go-version: '1.20.9'
21+
cache: true
22+
23+
- name: install deps
24+
run: |
25+
sudo apt-get update
26+
sudo apt-get -o Acquire::Retries=3 install make gcc git curl wget -y
27+
28+
- name: Build
29+
env:
30+
GOPROXY: "https://proxy.golang.org,direct"
31+
GO111MODULE: "on"
32+
run: |
33+
make build
34+
35+
- name: Lint
36+
run: |
37+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -d -b $(go env GOPATH)/bin v1.55.1
38+
golangci-lint run --timeout 10m
39+
40+
- name: Detect changes
41+
run: |
42+
git status --porcelain
43+
test -z "$(git status --porcelain)"

.github/workflows/test.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: basic-check
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- '**'
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-22.04
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Set up Go
18+
uses: actions/setup-go@v4
19+
with:
20+
go-version: '1.20.9'
21+
cache: true
22+
23+
- name: install deps
24+
run: |
25+
sudo apt-get update
26+
sudo apt-get -o Acquire::Retries=3 install make gcc git curl wget -y
27+
28+
- name: Build
29+
env:
30+
GOPROXY: "https://proxy.golang.org,direct"
31+
GO111MODULE: "on"
32+
run: |
33+
make build
34+
35+
- name: Test
36+
run: |
37+
go test -coverpkg=./... -coverprofile=coverage.txt -covermode=atomic -timeout=30m -parallel=4 -v ./...
38+
39+
- name: Upload
40+
uses: codecov/codecov-action@v3
41+
with:
42+
token:
43+
files: ./coverage.txt
44+
name: jzfs
45+
fail_ci_if_error: true
46+
verbose: true

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ jzfs
1616
# Test binary, built with `go test -c`
1717
*.test
1818

19-
# Output of the go coverage tool, specifically when used with LiteIDE
20-
*.out
19+
# Test coverage file
20+
coverage.txt
2121

2222
# Dependency directories (remove the comment below to include it)
2323
# vendor/

.golangci.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
linters:
2+
disable-all: true
3+
enable:
4+
- gofmt
5+
- govet
6+
- misspell
7+
- goconst
8+
- revive
9+
- errcheck
10+
- unconvert
11+
- staticcheck
12+
- unused
13+
- stylecheck
14+
- gosimple
15+
- goimports
16+
issues:
17+
exclude:
18+
- "should have( a package)? comment"
19+
20+
exclude-rules:
21+
exclude-use-default: false
22+
23+
linters-settings:
24+
goconst:
25+
min-occurrences: 6
26+
27+
run:
28+
skip-dirs:
29+
skip-files:

api/api_impl/common.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
package api_impl
1+
package apiimpl
22

33
import (
4+
"net/http"
5+
46
"github.com/jiaozifs/jiaozifs/api"
57
"github.com/jiaozifs/jiaozifs/version"
68
"go.uber.org/fx"
7-
"net/http"
89
)
910

1011
var _ api.ServerInterface = (*APIController)(nil)
@@ -13,7 +14,7 @@ type APIController struct {
1314
fx.In
1415
}
1516

16-
func (A APIController) GetVersion(w *api.JiaozifsResponse, r *http.Request) {
17+
func (A APIController) GetVersion(w *api.JiaozifsResponse, _ *http.Request) {
1718
swagger, err := api.GetSwagger()
1819
if err != nil {
1920
w.RespError(err)

api/api_impl/server.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
package api_impl
1+
package apiimpl
22

33
import (
44
"context"
55
"errors"
6+
7+
"net"
8+
"net/http"
9+
10+
"net/url"
11+
612
"github.com/getkin/kin-openapi/openapi3filter"
713
"github.com/go-chi/chi/v5"
814
"github.com/go-chi/cors"
@@ -11,9 +17,6 @@ import (
1117
"github.com/jiaozifs/jiaozifs/config"
1218
middleware "github.com/oapi-codegen/nethttp-middleware"
1319
"go.uber.org/fx"
14-
"net"
15-
"net/http"
16-
"net/url"
1720
)
1821

1922
var log = logging.Logger("rpc")

api/api_impl/utils.go

Lines changed: 0 additions & 22 deletions
This file was deleted.

api/custom_response.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ func (response *JiaozifsResponse) RespJSON(v interface{}) {
2222

2323
func (response *JiaozifsResponse) RespError(err error) {
2424
response.WriteHeader(http.StatusOK)
25-
response.Write([]byte(err.Error()))
25+
_, _ = response.Write([]byte(err.Error()))
2626
}

api/docs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Package apigen provides generated code for our OpenAPI
1+
// Package api provides generated code for our OpenAPI
22
package api
33

44
//go:generate go run github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen -package api -templates ./tmpls -generate "types,client,chi-server,spec" -o jiaozifs.gen.go ./swagger.yml

api/jiaozifs.gen.go

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)