Skip to content

Commit af90723

Browse files
authored
Merge pull request #5 from copyleftdev/fix/logger-and-lint-issues
Fix CI/CD pipeline issues
2 parents d1e3a3a + 0b63c5e commit af90723

File tree

36 files changed

+583
-483
lines changed

36 files changed

+583
-483
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
types: [ published ]
1010

1111
env:
12-
GO_VERSION: '1.21'
12+
GO_VERSION: '1.24'
1313
REGISTRY: ghcr.io
1414
IMAGE_NAME: ${{ github.repository }}
1515

@@ -73,10 +73,16 @@ jobs:
7373
- name: Checkout code
7474
uses: actions/checkout@v4
7575

76-
- name: Run Gosec Security Scanner
77-
uses: securecodewarrior/github-action-gosec@master
76+
- name: Set up Go
77+
uses: actions/setup-go@v5
7878
with:
79-
args: '-no-fail -fmt sarif -out gosec.sarif ./...'
79+
go-version: ${{ env.GO_VERSION }}
80+
cache: true
81+
82+
- name: Run Gosec Security Scanner
83+
run: |
84+
go install github.com/securego/gosec/v2/cmd/gosec@latest
85+
gosec -no-fail -fmt sarif -out gosec.sarif ./...
8086
8187
- name: Upload SARIF file
8288
uses: github/codeql-action/upload-sarif@v3
@@ -171,7 +177,7 @@ jobs:
171177
type=semver,pattern={{version}}
172178
type=semver,pattern={{major}}.{{minor}}
173179
type=semver,pattern={{major}}
174-
type=sha,prefix={{branch}}-
180+
type=sha
175181
176182
- name: Extract metadata (worker)
177183
id: meta-worker
@@ -184,7 +190,7 @@ jobs:
184190
type=semver,pattern={{version}}
185191
type=semver,pattern={{major}}.{{minor}}
186192
type=semver,pattern={{major}}
187-
type=sha,prefix={{branch}}-
193+
type=sha
188194
189195
- name: Build and push server image
190196
uses: docker/build-push-action@v6

.golangci.yml

Lines changed: 5 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -1,163 +1,16 @@
11
run:
22
timeout: 5m
3-
issues-exit-code: 1
4-
tests: true
5-
modules-download-mode: readonly
6-
7-
output:
8-
format: colored-line-number
9-
print-issued-lines: true
10-
print-linter-name: true
11-
uniq-by-line: true
12-
sort-results: true
13-
14-
linters-settings:
15-
govet:
16-
check-shadowing: true
17-
settings:
18-
printf:
19-
funcs:
20-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
21-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
22-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
23-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
24-
25-
golint:
26-
min-confidence: 0
27-
28-
gocyclo:
29-
min-complexity: 15
30-
31-
maligned:
32-
suggest-new: true
33-
34-
dupl:
35-
threshold: 100
36-
37-
goconst:
38-
min-len: 2
39-
min-occurrences: 2
40-
41-
depguard:
42-
list-type: blacklist
43-
packages:
44-
- github.com/sirupsen/logrus
45-
packages-with-error-message:
46-
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
47-
48-
misspell:
49-
locale: US
50-
51-
lll:
52-
line-length: 140
53-
54-
goimports:
55-
local-prefixes: print-service
56-
57-
gocritic:
58-
enabled-tags:
59-
- diagnostic
60-
- experimental
61-
- opinionated
62-
- performance
63-
- style
64-
disabled-checks:
65-
- dupImport
66-
- ifElseChain
67-
- octalLiteral
68-
- whyNoLint
69-
- wrapperFunc
70-
71-
funlen:
72-
lines: 100
73-
statements: 50
74-
75-
gocognit:
76-
min-complexity: 20
77-
78-
nestif:
79-
min-complexity: 4
80-
81-
godox:
82-
keywords:
83-
- NOTE
84-
- OPTIMIZE
85-
- HACK
86-
87-
dogsled:
88-
max-blank-identifiers: 2
89-
90-
whitespace:
91-
multi-if: false
92-
multi-func: false
933

944
linters:
95-
disable-all: true
965
enable:
97-
- bodyclose
98-
- deadcode
99-
- depguard
100-
- dogsled
101-
- dupl
1026
- errcheck
103-
- funlen
104-
- gochecknoinits
105-
- goconst
106-
- gocritic
107-
- gocyclo
108-
- gofmt
109-
- goimports
110-
- golint
111-
- gomnd
112-
- goprintffuncname
113-
- gosec
1147
- gosimple
1158
- govet
1169
- ineffassign
117-
- interfacer
118-
- lll
119-
- misspell
120-
- nakedret
121-
- noctx
122-
- nolintlint
123-
- rowserrcheck
124-
- scopelint
12510
- staticcheck
126-
- structcheck
127-
- stylecheck
128-
- typecheck
129-
- unconvert
130-
- unparam
131-
- unused
132-
- varcheck
133-
- whitespace
134-
135-
issues:
136-
exclude-rules:
137-
- path: _test\.go
138-
linters:
139-
- gomnd
140-
- funlen
141-
- gocyclo
142-
143-
- path: cmd/
144-
linters:
145-
- gochecknoinits
146-
147-
- linters:
148-
- lll
149-
source: "^//go:generate "
150-
151-
exclude-use-default: false
152-
exclude:
153-
- 'declaration of "(err|ctx)" shadows declaration at'
154-
- 'G104: Errors unhandled'
155-
- 'G204: Subprocess launched with variable'
156-
- 'G304: Potential file inclusion via variable'
157-
158-
max-issues-per-linter: 50
159-
max-same-issues: 3
11+
- gofmt
16012

161-
severity:
162-
default-severity: error
163-
case-sensitive: false
13+
linters-settings:
14+
errcheck:
15+
exclude-functions:
16+
- (*go.uber.org/zap.Logger).Sync

cmd/server/main.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"time"
1212

1313
"print-service/internal/api"
14-
"print-service/internal/pkg/config"
1514
"print-service/internal/infrastructure/logger"
15+
"print-service/internal/pkg/config"
1616
)
1717

1818
func main() {
@@ -23,12 +23,12 @@ func main() {
2323
}
2424

2525
// Initialize logger
26-
logger := logger.NewStructuredLogger(cfg.Logger)
27-
defer logger.Sync()
26+
log := logger.NewStructuredLogger(&cfg.Logger)
27+
defer func() { _ = log.Sync() }()
2828

2929
// Create HTTP server
30-
server := api.NewServer(cfg, logger)
31-
30+
server := api.NewServer(cfg, log)
31+
3232
httpServer := &http.Server{
3333
Addr: fmt.Sprintf(":%d", cfg.Server.Port),
3434
Handler: server.Handler(),
@@ -39,28 +39,27 @@ func main() {
3939

4040
// Start server in a goroutine
4141
go func() {
42-
logger.Info("Starting HTTP server", "port", cfg.Server.Port)
42+
log.Info("Starting HTTP server", "port", cfg.Server.Port)
4343
if err := httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
44-
logger.Error("Failed to start server", "error", err)
45-
os.Exit(1)
44+
log.Error("Server failed to start", "error", err)
4645
}
46+
os.Exit(1)
4747
}()
4848

4949
// Wait for interrupt signal to gracefully shutdown the server
5050
quit := make(chan os.Signal, 1)
5151
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
5252
<-quit
5353

54-
logger.Info("Shutting down server...")
54+
log.Info("Shutting down server...")
5555

5656
// Give outstanding requests a deadline for completion
5757
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
5858
defer cancel()
5959

6060
if err := httpServer.Shutdown(ctx); err != nil {
61-
logger.Error("Server forced to shutdown", "error", err)
62-
os.Exit(1)
61+
log.Error("Server forced to shutdown", "error", err)
6362
}
6463

65-
logger.Info("Server exited")
64+
log.Info("Server exited")
6665
}

cmd/worker/main.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
"time"
1010

1111
"print-service/internal/core/services"
12+
"print-service/internal/infrastructure/logger"
1213
"print-service/internal/pkg/config"
1314
"print-service/internal/pkg/pool"
14-
"print-service/internal/infrastructure/logger"
1515
)
1616

1717
func main() {
@@ -22,23 +22,23 @@ func main() {
2222
}
2323

2424
// Initialize logger
25-
logger := logger.NewStructuredLogger(cfg.Logger)
26-
defer logger.Sync()
25+
log := logger.NewStructuredLogger(&cfg.Logger)
26+
defer func() { _ = log.Sync() }()
2727

2828
// Create worker pool
29-
workerPool := pool.NewWorkerPool(cfg.Worker.PoolSize, logger)
29+
workerPool := pool.NewWorkerPool(cfg.Worker.PoolSize, log)
3030

3131
// Initialize queue service
32-
queueService, err := services.NewQueueService(cfg.Queue, logger)
32+
queueService, err := services.NewQueueService(cfg.Queue, log)
3333
if err != nil {
34-
logger.Error("Failed to initialize queue service", "error", err)
34+
log.Error("Failed to initialize queue service", "error", err)
3535
os.Exit(1)
3636
}
3737

3838
// Initialize print service
39-
printService, err := services.NewPrintService(cfg.Print, logger)
39+
printService, err := services.NewPrintService(cfg.Print, log)
4040
if err != nil {
41-
logger.Error("Failed to initialize print service", "error", err)
41+
log.Error("Failed to initialize print service", "error", err)
4242
os.Exit(1)
4343
}
4444

@@ -53,21 +53,21 @@ func main() {
5353

5454
// Start queue consumer
5555
go func() {
56-
logger.Info("Starting queue consumer")
56+
log.Info("Starting queue consumer")
5757
if err := queueService.StartConsumer(ctx, workerPool.Submit); err != nil {
58-
logger.Error("Queue consumer failed", "error", err)
58+
log.Error("Queue consumer failed", "error", err)
5959
cancel()
6060
}
6161
}()
6262

63-
logger.Info("Worker started", "pool_size", cfg.Worker.PoolSize)
63+
log.Info("Worker started", "pool_size", cfg.Worker.PoolSize)
6464

6565
// Wait for interrupt signal
6666
quit := make(chan os.Signal, 1)
6767
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
6868
<-quit
6969

70-
logger.Info("Shutting down worker...")
70+
log.Info("Shutting down worker...")
7171

7272
// Cancel context to stop all workers
7373
cancel()
@@ -79,5 +79,5 @@ func main() {
7979
workerPool.Stop(shutdownCtx)
8080
queueService.Stop(shutdownCtx)
8181

82-
logger.Info("Worker exited")
82+
log.Info("Worker exited")
8383
}

deployments/docker/Dockerfile.server

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build stage
2-
FROM golang:1.21-alpine AS builder
2+
FROM golang:1.24-alpine AS builder
33

44
# Install build dependencies
55
RUN apk add --no-cache git ca-certificates tzdata

deployments/docker/Dockerfile.worker

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build stage
2-
FROM golang:1.21-alpine AS builder
2+
FROM golang:1.24-alpine AS builder
33

44
# Install build dependencies
55
RUN apk add --no-cache git ca-certificates tzdata

go.mod

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@ require (
1212
)
1313

1414
require (
15-
github.com/bytedance/sonic v1.11.6 // indirect
16-
github.com/bytedance/sonic/loader v0.1.1 // indirect
17-
github.com/cloudwego/base64x v0.1.4 // indirect
18-
github.com/cloudwego/iasm v0.2.0 // indirect
19-
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
20-
github.com/gin-contrib/sse v0.1.0 // indirect
15+
github.com/bytedance/sonic v1.14.0 // indirect
16+
github.com/bytedance/sonic/loader v0.3.0 // indirect
17+
github.com/cloudwego/base64x v0.1.5 // indirect
18+
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
19+
github.com/gin-contrib/sse v1.1.0 // indirect
2120
github.com/go-playground/locales v0.14.1 // indirect
2221
github.com/go-playground/universal-translator v0.18.1 // indirect
23-
github.com/go-playground/validator/v10 v10.20.0 // indirect
24-
github.com/goccy/go-json v0.10.2 // indirect
22+
github.com/go-playground/validator/v10 v10.27.0 // indirect
23+
github.com/goccy/go-json v0.10.5 // indirect
2524
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
2625
github.com/json-iterator/go v1.1.12 // indirect
2726
github.com/klauspost/cpuid/v2 v2.2.7 // indirect

0 commit comments

Comments
 (0)