Skip to content

Commit 0268b18

Browse files
committed
MINOR: testing: add CD linter, fix linting errors.
1 parent 9673a0b commit 0268b18

14 files changed

Lines changed: 138 additions & 32 deletions

File tree

.github/workflows/build.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: go build
2+
on: [push, pull_request]
3+
jobs:
4+
5+
build:
6+
name: Build
7+
runs-on: ubuntu-latest
8+
steps:
9+
10+
- name: Set up Go 1.13
11+
uses: actions/setup-go@v1
12+
with:
13+
go-version: 1.13
14+
id: go
15+
16+
- name: Check out code into the Go module directory
17+
uses: actions/checkout@v1
18+
19+
- name: Get dependencies
20+
run: |
21+
go get -v -t -d ./...
22+
- name: Build
23+
run: |
24+
go build -v .

.github/workflows/lint.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: golangci-lint
2+
on: [push, pull_request]
3+
jobs:
4+
golangci-lint:
5+
name: runner / golangci-lint
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Check out code into the Go module directory
9+
uses: actions/checkout@v1
10+
- name: golangci-lint
11+
uses: reviewdog/action-golangci-lint@v1
12+
with:
13+
github_token: ${{ secrets.github_token }}

.gitlab-ci.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
reviewdog:
3+
image:
4+
name: golangci/golangci-lint:v1.21.0
5+
entrypoint: [""]
6+
tags:
7+
- docker
8+
script:
9+
- go env
10+
- go mod verify
11+
- golangci-lint run -v --color always --timeout 120s
12+
#- go get -u github.com/reviewdog/reviewdog/cmd/reviewdog
13+
#- reviewdog -reporter=gitlab-mr-discussion
14+
- go build .

.golangci.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
linters-settings:
2+
govet:
3+
check-shadowing: true
4+
golint:
5+
min-confidence: 0
6+
gocyclo:
7+
min-complexity: 25
8+
maligned:
9+
suggest-new: true
10+
dupl:
11+
threshold: 200
12+
goconst:
13+
min-len: 2
14+
min-occurrences: 2
15+
16+
linters:
17+
enable:
18+
- golint
19+
- gocritic
20+
- stylecheck
21+
- goimports
22+
- gosec
23+
- unconvert
24+
disable:
25+
- maligned
26+
- prealloc
27+
- gochecknoglobals
28+
29+
issues:
30+
exclude-rules:
31+
- linters:
32+
- staticcheck
33+
text: "duplicate struct tag"
34+
35+
run:
36+
skip-dirs:
37+
- test
38+
39+
# golangci.com configuration
40+
# https://github.com/golangci/golangci/wiki/Configuration
41+
service:
42+
golangci-lint-version: 1.17.x # use the fixed version to not introduce new linters unexpectedly

adapters/adapters.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ func RecoverMiddleware(logger *logrus.Logger) func(h http.Handler) http.Handler
145145
if strings.HasPrefix(ct, "application/json") {
146146
w.Header().Set(http.CanonicalHeaderKey("Content-Type"), "application/json")
147147
}
148+
// nolint:errcheck
148149
w.Write(errMsg)
149150
}
150151
}()

cmd/dataplaneapi/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ func main() {
4545
if err != nil {
4646
log.Fatalln(err)
4747
}
48-
48+
4949
dataplaneapi.BuildTime = BuildTime
5050
dataplaneapi.Version = fmt.Sprintf("%s %s%s", GitTag, GitCommit, GitDirty)
51-
51+
5252
api := operations.NewDataPlaneAPI(swaggerSpec)
5353
server := dataplaneapi.NewServer(api)
54+
//nolint
5455
defer server.Shutdown()
5556

5657
parser := flags.NewParser(server, flags.Default)
@@ -59,7 +60,7 @@ func main() {
5960

6061
server.ConfigureFlags()
6162
for _, optsGroup := range api.CommandLineOptionsGroups {
62-
_, err := parser.AddGroup(optsGroup.ShortDescription, optsGroup.LongDescription, optsGroup.Options)
63+
_, err = parser.AddGroup(optsGroup.ShortDescription, optsGroup.LongDescription, optsGroup.Options)
6364
if err != nil {
6465
log.Fatalln(err)
6566
}

configure_data_plane.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -421,14 +421,14 @@ func setupGlobalMiddleware(handler http.Handler) http.Handler {
421421
func authenticateUser(user string, pass string, cli *client_native.HAProxyClient) (interface{}, error) {
422422
data, err := cli.Configuration.Parser.Get(parser.UserList, haproxyOptions.Userlist, "user")
423423
if err != nil {
424-
return nil, fmt.Errorf("Error reading userlist %v userlist in conf: %s", haproxyOptions.Userlist, err.Error())
424+
return nil, fmt.Errorf("error reading userlist %v userlist in conf: %s", haproxyOptions.Userlist, err.Error())
425425
}
426426
users, ok := data.([]types.User)
427427
if !ok {
428-
return nil, fmt.Errorf("Error reading users from %v userlist in conf", haproxyOptions.Userlist)
428+
return nil, fmt.Errorf("error reading users from %v userlist in conf", haproxyOptions.Userlist)
429429
}
430430
if len(users) == 0 {
431-
return nil, fmt.Errorf("No users configured in %v userlist in conf", haproxyOptions.Userlist)
431+
return nil, fmt.Errorf("no users configured in %v userlist in conf", haproxyOptions.Userlist)
432432
}
433433

434434
for _, u := range users {
@@ -467,7 +467,7 @@ func configureLogging() {
467467
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
468468
log.Warning("Error opening log file, no logging implemented: " + err.Error())
469469
}
470-
470+
//nolint:govet
471471
logFile, err := os.OpenFile(loggingOptions.LogFile, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666)
472472
if err != nil {
473473
log.Warning("Error opening log file, no logging implemented: " + err.Error())
@@ -555,7 +555,7 @@ func configureConfigurationClient() (*configuration.Client, error) {
555555
}
556556
err := confClient.Init(confParams)
557557
if err != nil {
558-
return nil, fmt.Errorf("Error setting up configuration client: %s", err.Error())
558+
return nil, fmt.Errorf("error setting up configuration client: %s", err.Error())
559559
}
560560
return confClient, nil
561561
}
@@ -602,6 +602,7 @@ func configureRuntimeClient(confClient *configuration.Client) *runtime_api.Clien
602602
// else try to find process specific sockets and set them up
603603
sockets := make(map[int]string)
604604
for _, r := range runtimeAPIs {
605+
//nolint:govet
605606
if misc.IsUnixSocketAddr(*r.Address) && r.Process != "" {
606607
process, err := strconv.ParseInt(r.Process, 10, 64)
607608
if err == nil {
@@ -614,15 +615,15 @@ func configureRuntimeClient(confClient *configuration.Client) *runtime_api.Clien
614615
log.Warning("Runtime API not configured, found multiple processes and no stats sockets bound to them.")
615616
return nil
616617
// use only found process specific sockets issue a warning if not all processes have a socket configured
617-
} else {
618-
if len(sockets) < int(globalConf.Nbproc) {
619-
log.Warning("Runtime API not configured properly, there are more processes then configured sockets")
620-
}
621-
if err = runtimeClient.InitWithSockets(sockets); err == nil {
622-
return runtimeClient
623-
}
624-
log.Warningf("Error setting up runtime client with sockets: %s : %s", sockets, err.Error())
625618
}
619+
if len(sockets) < int(globalConf.Nbproc) {
620+
log.Warning("Runtime API not configured properly, there are more processes then configured sockets")
621+
}
622+
if err = runtimeClient.InitWithSockets(sockets); err == nil {
623+
return runtimeClient
624+
}
625+
log.Warningf("Error setting up runtime client with sockets: %v : %s", sockets, err.Error())
626+
626627
}
627628
if err != nil {
628629
log.Warning("Runtime API not configured, not using it: " + err.Error())
@@ -636,6 +637,7 @@ func configureRuntimeClient(confClient *configuration.Client) *runtime_api.Clien
636637
}
637638

638639
func handleSignals(sigs chan os.Signal, client *client_native.HAProxyClient) {
640+
//nolint:gosimple
639641
for {
640642
select {
641643
case sig := <-sigs:

handlers/information.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func (h *GetInfoHandlerImpl) Handle(params information.GetInfoParams, principal
9292
sys.MemInfo.TotalMemory = int64(mem.Total)
9393
sys.MemInfo.FreeMemory = int64(mem.Free)
9494
}
95+
//nolint:govet
9596
if uptime, err := host.Uptime(); err == nil {
9697
uptimeInt64 := int64(uptime)
9798
sys.Uptime = &uptimeInt64

handlers/runtime.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func changeThroughRuntimeAPI(data, ondisk interface{}, parentName, parentType st
6363
for _, field := range diff {
6464
fieldValue := reflect.ValueOf(vData).FieldByName(field)
6565
if fieldValue.IsValid() {
66+
//nolint:gocritic
6667
switch field {
6768
case "Maxconn":
6869
maxConn := fieldValue.Elem().Int()

handlers/runtime_server.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (h *ReplaceRuntimeServerHandlerImpl) Handle(params server.ReplaceRuntimeSer
8787

8888
// change operational state
8989
if rs.OperationalState != params.Data.OperationalState {
90-
err := h.Client.Runtime.SetServerHealth(params.Backend, params.Name, params.Data.OperationalState)
90+
err = h.Client.Runtime.SetServerHealth(params.Backend, params.Name, params.Data.OperationalState)
9191
if err != nil {
9292
e := misc.HandleError(err)
9393
return server.NewReplaceRuntimeServerDefault(int(*e.Code)).WithPayload(e)
@@ -96,11 +96,12 @@ func (h *ReplaceRuntimeServerHandlerImpl) Handle(params server.ReplaceRuntimeSer
9696

9797
// change admin state
9898
if rs.AdminState != params.Data.AdminState {
99-
err := h.Client.Runtime.SetServerState(params.Backend, params.Name, params.Data.AdminState)
99+
err = h.Client.Runtime.SetServerState(params.Backend, params.Name, params.Data.AdminState)
100100
if err != nil {
101101
e := misc.HandleError(err)
102102

103103
// try to revert operational state and fall silently
104+
//nolint:errcheck
104105
h.Client.Runtime.SetServerHealth(params.Backend, params.Name, rs.OperationalState)
105106
return server.NewReplaceRuntimeServerDefault(int(*e.Code)).WithPayload(e)
106107
}

0 commit comments

Comments
 (0)