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.

cmd/daemon.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
/*
2-
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
3-
*/
41
package cmd
52

63
import (
74
"context"
5+
86
logging "github.com/ipfs/go-log/v2"
9-
"github.com/jiaozifs/jiaozifs/api/api_impl"
7+
apiImpl "github.com/jiaozifs/jiaozifs/api/api_impl"
108
"github.com/jiaozifs/jiaozifs/config"
119
"github.com/jiaozifs/jiaozifs/fx_opt"
1210
"github.com/jiaozifs/jiaozifs/models"
@@ -48,7 +46,7 @@ var daemonCmd = &cobra.Command{
4846
fx_opt.Override(fx_opt.NextInvoke(), migrations.MigrateDatabase),
4947
fx_opt.Override(new(*models.IUserRepo), models.NewUserRepo),
5048
//api
51-
fx_opt.Override(fx_opt.NextInvoke(), api_impl.SetupAPI),
49+
fx_opt.Override(fx_opt.NextInvoke(), apiImpl.SetupAPI),
5250
)
5351
if err != nil {
5452
return err
@@ -59,7 +57,6 @@ var daemonCmd = &cobra.Command{
5957
<-shutdown
6058
log.Info("graceful shutdown")
6159
return stop(cmd.Context())
62-
return nil
6360
},
6461
}
6562

@@ -68,6 +65,6 @@ func init() {
6865
daemonCmd.Flags().String("db", "", "pg connection string eg. postgres://user:pass@localhost:5432/jiaozifs?sslmode=disable")
6966
daemonCmd.Flags().String("log-level", "INFO", "set log level eg. DEBUG INFO ERROR")
7067

71-
viper.BindPFlag("database.connection", daemonCmd.Flags().Lookup("db"))
72-
viper.BindPFlag("log.level", daemonCmd.Flags().Lookup("log-level"))
68+
_ = viper.BindPFlag("database.connection", daemonCmd.Flags().Lookup("db"))
69+
_ = viper.BindPFlag("log.level", daemonCmd.Flags().Lookup("log-level"))
7370
}

cmd/init.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
/*
2-
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
3-
*/
41
package cmd
52

63
import (
@@ -14,9 +11,9 @@ var initCmd = &cobra.Command{
1411
Use: "init",
1512
Short: "init jiaozifs ",
1613
Long: `create default config file for jiaoozifs`,
17-
PreRun: func(cmd *cobra.Command, args []string) {
18-
//provent duplicate bind flag with daemon
19-
viper.BindPFlag("database.connection", cmd.Flags().Lookup("db"))
14+
PreRunE: func(cmd *cobra.Command, args []string) error {
15+
//protect duplicate bind flag with daemon
16+
return viper.BindPFlag("database.connection", cmd.Flags().Lookup("db"))
2017
},
2118
RunE: func(cmd *cobra.Command, args []string) error {
2219
return config.InitConfig()

cmd/root.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
/*
2-
Copyright © 2023 githun.com/jiaozifs/jiaozifs
3-
*/
41
package cmd
52

63
import (
4+
"os"
5+
76
"github.com/spf13/cobra"
87
"github.com/spf13/viper"
9-
"os"
108
)
119

1210
var cfgFile string
@@ -29,5 +27,5 @@ func Execute() {
2927

3028
func init() {
3129
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.jiaozifs/config.yaml)")
32-
viper.BindPFlag("config", rootCmd.Flags().Lookup("config"))
30+
_ = viper.BindPFlag("config", rootCmd.Flags().Lookup("config"))
3331
}

cmd/version.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
/*
2-
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
3-
*/
41
package cmd
52

63
import (
74
"fmt"
5+
86
"github.com/jiaozifs/jiaozifs/api"
9-
"github.com/jiaozifs/jiaozifs/api/api_impl"
7+
apiimpl "github.com/jiaozifs/jiaozifs/api/api_impl"
108
"github.com/jiaozifs/jiaozifs/config"
119
"github.com/jiaozifs/jiaozifs/version"
1210
"github.com/spf13/cobra"
@@ -30,7 +28,7 @@ var versionCmd = &cobra.Command{
3028
if err != nil {
3129
return err
3230
}
33-
client, err := api.NewClient(cfg.API.Listen + api_impl.APIV1Prefix)
31+
client, err := api.NewClient(cfg.API.Listen + apiimpl.APIV1Prefix)
3432
if err != nil {
3533
return err
3634
}

config/config.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@ package config
22

33
import (
44
"fmt"
5-
logging "github.com/ipfs/go-log/v2"
5+
6+
"os"
7+
"path"
8+
69
ms "github.com/mitchellh/mapstructure"
710
"github.com/spf13/cobra"
811
"github.com/spf13/viper"
9-
"os"
10-
"path"
1112
)
1213

13-
var log = logging.Logger("log")
14-
1514
type Config struct {
1615
Path string `mapstructure:"config"`
1716
Log LogConfig `mapstructure:"log"`

models/migrations/20210505110026_init_project.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package migrations
22

33
import (
44
"context"
5+
56
"github.com/jiaozifs/jiaozifs/models"
67
"github.com/uptrace/bun"
78
)

models/migrations/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package migrations
22

33
import (
44
"context"
5+
56
"github.com/uptrace/bun"
67
"github.com/uptrace/bun/migrate"
78
)

models/models.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package models
33
import (
44
"context"
55
"database/sql"
6+
67
"github.com/jiaozifs/jiaozifs/config"
78
"github.com/uptrace/bun"
89
"github.com/uptrace/bun/dialect/pgdialect"

0 commit comments

Comments
 (0)