Skip to content

Commit cb14d12

Browse files
authored
Merge pull request #43 from kilnfi/chore/lint
chore: lint
2 parents 357b566 + 050c134 commit cb14d12

File tree

12 files changed

+115
-131
lines changed

12 files changed

+115
-131
lines changed

.github/workflows/lint.yaml

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,39 +21,6 @@ jobs:
2121
with:
2222
go-version: 1.24
2323
- name: golangci-lint
24-
uses: golangci/golangci-lint-action@v6
24+
uses: golangci/golangci-lint-action@v8
2525
with:
26-
version: v1.60
27-
helm-chart:
28-
if: false
29-
runs-on: ubuntu-latest
30-
steps:
31-
- name: Checkout
32-
uses: actions/checkout@v4
33-
with:
34-
fetch-depth: 0
35-
36-
- name: Set up Helm
37-
uses: azure/[email protected]
38-
with:
39-
version: v3.16.4
40-
41-
- uses: actions/setup-python@v5
42-
with:
43-
python-version: '3.x'
44-
check-latest: true
45-
46-
- name: Set up chart-testing
47-
uses: helm/[email protected]
48-
49-
- name: Run chart-testing (list-changed)
50-
id: list-changed
51-
run: |
52-
changed=$(ct list-changed --target-branch ${{ github.event.repository.default_branch }})
53-
if [[ -n "$changed" ]]; then
54-
echo "changed=true" | tee "$GITHUB_OUTPUT"
55-
fi
56-
57-
- name: Run chart lint
58-
if: steps.list-changed.outputs.changed == 'true'
59-
run: ct lint --target-branch ${{ github.event.repository.default_branch }}
26+
version: v2.3

.golangci.yaml

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,76 @@
1+
version: "2"
2+
run:
3+
go: "1.24"
14
linters:
2-
disable-all: true
5+
default: none
36
enable:
47
- asasalint
58
- asciicheck
69
- bidichk
710
- bodyclose
11+
- contextcheck
12+
- copyloopvar
813
- dogsled
9-
- durationcheck
1014
- dupword
15+
- durationcheck
1116
- errcheck
12-
- copyloopvar
1317
- errchkjson
18+
- ginkgolinter
1419
- goconst
15-
- gofmt
16-
- sloglint
20+
- gocritic
1721
- goheader
18-
- goimports
1922
- goprintffuncname
2023
- gosec
21-
- gosimple
22-
- gocritic
2324
- govet
24-
- ginkgolinter
2525
- importas
2626
- ineffassign
2727
- misspell
2828
- nakedret
29-
- nosprintfhostport
3029
- nilerr
3130
- noctx
3231
- nolintlint
32+
- nosprintfhostport
33+
- prealloc
34+
- promlinter
3335
- revive
36+
- sloglint
37+
- sqlclosecheck
3438
- staticcheck
35-
- stylecheck
3639
- testifylint
37-
- tparallel
3840
- thelper
39-
- typecheck
41+
- tparallel
4042
- unconvert
4143
- unparam
4244
- unused
4345
- usestdlibvars
4446
- whitespace
4547
- wrapcheck
46-
- sqlclosecheck
47-
- promlinter
48-
- prealloc
49-
- contextcheck
50-
51-
linters-settings:
52-
gocritic:
53-
disabled-checks: [captLocal]
54-
revive:
55-
rules:
56-
- name: blank-imports
57-
disabled: true
58-
issues: {}
59-
run:
60-
timeout: 5m
48+
settings:
49+
gocritic:
50+
disabled-checks:
51+
- captLocal
52+
revive:
53+
rules:
54+
- name: blank-imports
55+
disabled: true
56+
exclusions:
57+
generated: lax
58+
presets:
59+
- comments
60+
- common-false-positives
61+
- legacy
62+
- std-error-handling
63+
paths:
64+
- third_party$
65+
- builtin$
66+
- examples$
67+
formatters:
68+
enable:
69+
- gofmt
70+
- goimports
71+
exclusions:
72+
generated: lax
73+
paths:
74+
- third_party$
75+
- builtin$
76+
- examples$

cmd/watcher/app/watcher.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,20 +137,20 @@ func loadConfig() {
137137

138138
// read the config file
139139
if err := viper.ReadInConfig(); err != nil {
140-
logger.Error("unable to read config file", slog.String("error", err.Error()))
140+
logger.ErrorContext(context.Background(), "unable to read config file", slog.String("error", err.Error()))
141141
os.Exit(1)
142142
}
143143

144144
// unmarshal the config
145145
cfg = &config.Config{}
146146
if err := viper.Unmarshal(cfg); err != nil {
147-
logger.Error("unable to unmarshal config", slog.String("error", err.Error()))
147+
logger.ErrorContext(context.Background(), "unable to unmarshal config", slog.String("error", err.Error()))
148148
os.Exit(1)
149149
}
150150

151151
// validate the config
152152
if err := cfg.Validate(); err != nil {
153-
logger.Error("invalid configuration", slog.String("error", err.Error()))
153+
logger.ErrorContext(context.Background(), "invalid configuration", slog.String("error", err.Error()))
154154
os.Exit(1)
155155
}
156156
}
@@ -226,19 +226,19 @@ func run(_ *cobra.Command, _ []string) error {
226226
}
227227

228228
<-ctx.Done()
229-
logger.Info("shutting down")
229+
logger.InfoContext(ctx, "shutting down")
230230

231231
// shutting down HTTP server
232232
ctx, cancel = context.WithTimeout(context.Background(), 30*time.Second)
233233
defer cancel()
234-
logger.Info("stopping http server")
234+
logger.InfoContext(ctx, "stopping http server")
235235
if err := server.Stop(ctx); err != nil {
236-
logger.Error("unable to stop http service", slog.String("error", err.Error()))
236+
logger.ErrorContext(ctx, "unable to stop http service", slog.String("error", err.Error()))
237237
}
238238

239239
if err := eg.Wait(); err != nil {
240240
if errors.Is(err, context.Canceled) {
241-
logger.Info("Program interrupted by user")
241+
logger.InfoContext(ctx, "Program interrupted by user")
242242
return nil
243243
}
244244
return fmt.Errorf("error during execution: %w", err)
@@ -281,7 +281,7 @@ func startHTTPServer(eg *errgroup.Group, registry *prometheus.Registry, healthSt
281281
}
282282

283283
eg.Go(func() error {
284-
logger.Info(
284+
logger.InfoContext(context.Background(),
285285
"starting http server",
286286
slog.String("component", "http-server"),
287287
slog.String("addr", fmt.Sprintf("%s:%d", cfg.HTTP.Host, cfg.HTTP.Port)),
@@ -306,7 +306,7 @@ func startStatusWatcher(
306306
) {
307307
eg.Go(func() error {
308308
statusWatcher := watcher.NewStatusWatcher(blockfrost, cardano, metrics, healthStore)
309-
logger.Info(
309+
logger.InfoContext(ctx,
310310
"starting watcher",
311311
slog.String("component", "status-watcher"),
312312
)
@@ -331,7 +331,7 @@ func startPoolWatcher(
331331
RefreshInterval: time.Second * time.Duration(cfg.PoolWatcherConfig.RefreshInterval),
332332
Network: cfg.Network,
333333
}
334-
logger.Info(
334+
logger.InfoContext(ctx,
335335
"starting watcher",
336336
slog.String("component", "pool-watcher"),
337337
)
@@ -359,7 +359,7 @@ func startNetworkWatcher(
359359
RefreshInterval: time.Second * time.Duration(cfg.PoolWatcherConfig.RefreshInterval),
360360
Network: cfg.Network,
361361
}
362-
logger.Info(
362+
logger.InfoContext(ctx,
363363
"starting watcher",
364364
slog.String("component", "network-watcher"),
365365
)
@@ -388,7 +388,7 @@ func startBlockWatcher(
388388
RefreshInterval: time.Second * time.Duration(cfg.BlockWatcherConfig.RefreshInterval),
389389
}
390390
blockWatcher := watcher.NewBlockWatcher(cardano, blockfrost, sl, pools, metrics, db, healthStore, options)
391-
logger.Info(
391+
logger.InfoContext(ctx,
392392
"starting watcher",
393393
slog.String("component", "block-watcher"),
394394
)
@@ -403,7 +403,7 @@ func startBlockWatcher(
403403
// used for the flag parsing
404404
func checkError(err error, msg string) {
405405
if err != nil {
406-
logger.Error(msg, slog.String("error", err.Error()))
406+
logger.ErrorContext(context.Background(), msg, slog.String("error", err.Error()))
407407
os.Exit(1)
408408
}
409409
}

cmd/watcher/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"context"
45
"log/slog"
56
"os"
67

@@ -14,7 +15,7 @@ func main() {
1415

1516
command := app.NewWatcherCommand()
1617
if err := command.Execute(); err != nil {
17-
logger.Error("command execution failed", slog.String("error", err.Error()))
18+
logger.ErrorContext(context.Background(), "command execution failed", slog.String("error", err.Error()))
1819
os.Exit(1)
1920
}
2021
}

internal/cardano/cardanocli/cardano.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (c *Client) Ping(ctx context.Context) error {
6767
}
6868

6969
cmd := fmt.Sprintf("cardano-cli %s", strings.Join(args, " "))
70-
c.logger.Debug("pinging cardano node", slog.String("cmd", cmd))
70+
c.logger.DebugContext(ctx, "pinging cardano node", slog.String("cmd", cmd))
7171

7272
_, err := c.executor.ExecCommand(ctx, nil, "cardano-cli", args...)
7373
if err != nil {
@@ -173,7 +173,7 @@ func (c *Client) LeaderLogs(ctx context.Context, ledgetSet string, epochNonce st
173173
}
174174
output, err := c.executor.ExecCommand(ctx, envs, "cncli", args...)
175175
if err != nil {
176-
c.logger.Error(
176+
c.logger.ErrorContext(ctx,
177177
fmt.Sprintf("unable to execute cncli leaderlog command: %v", err),
178178
slog.String("pool_name", pool.Name),
179179
slog.String("pool_id", pool.ID),

internal/database/database.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (db *database) Connect(ctx context.Context) error {
3838
if err != nil {
3939
return fmt.Errorf("failed to connect to database: %w", err)
4040
}
41-
db.DB.SetMaxOpenConns(db.opts.MaxOpenConns)
41+
db.SetMaxOpenConns(db.opts.MaxOpenConns)
4242

4343
return nil
4444
}

internal/slotleader/slotleader.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ func (s *Service) Refresh(ctx context.Context, epoch bfAPI.Epoch) error {
5858
}
5959

6060
if !refreshed {
61-
s.logger.Info(
61+
s.logger.InfoContext(ctx,
6262
fmt.Sprintf("⏰ refreshing slots for pool: %s", pool.Name),
6363
slog.String("pool_id", pool.ID),
6464
)
6565
if err := s.cardano.LeaderLogs(ctx, "current", epochParams.Nonce, pool); err != nil {
6666
return &ErrSlotLeaderRefresh{PoolID: pool.ID, Epoch: epoch.Epoch, Message: err.Error()}
6767
}
6868
} else {
69-
s.logger.Info(
69+
s.logger.InfoContext(ctx,
7070
fmt.Sprintf("💠 slots already refreshed for pool: %s", pool.Name),
7171
slog.String("pool_id", pool.ID),
7272
)
@@ -105,7 +105,7 @@ func (s *Service) GetNextSlotLeader(ctx context.Context, PoolID string, height i
105105
}
106106

107107
lastSlot := schedule.Slots[len(schedule.Slots)-1]
108-
s.logger.Debug(
108+
s.logger.DebugContext(ctx,
109109
fmt.Sprintf("last slot for pool %s is %d", PoolID, lastSlot),
110110
slog.String("pool_id", PoolID),
111111
slog.Int("last_slot", lastSlot),

0 commit comments

Comments
 (0)