Skip to content

chore: lint #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 2 additions & 35 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,6 @@ jobs:
with:
go-version: 1.24
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v8
with:
version: v1.60
helm-chart:
if: false
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Helm
uses: azure/[email protected]
with:
version: v3.16.4

- uses: actions/setup-python@v5
with:
python-version: '3.x'
check-latest: true

- name: Set up chart-testing
uses: helm/[email protected]

- name: Run chart-testing (list-changed)
id: list-changed
run: |
changed=$(ct list-changed --target-branch ${{ github.event.repository.default_branch }})
if [[ -n "$changed" ]]; then
echo "changed=true" | tee "$GITHUB_OUTPUT"
fi

- name: Run chart lint
if: steps.list-changed.outputs.changed == 'true'
run: ct lint --target-branch ${{ github.event.repository.default_branch }}
version: v2.3
72 changes: 44 additions & 28 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,60 +1,76 @@
version: "2"
run:
go: "1.24"
linters:
disable-all: true
default: none
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- contextcheck
- copyloopvar
- dogsled
- durationcheck
- dupword
- durationcheck
- errcheck
- copyloopvar
- errchkjson
- ginkgolinter
- goconst
- gofmt
- sloglint
- gocritic
- goheader
- goimports
- goprintffuncname
- gosec
- gosimple
- gocritic
- govet
- ginkgolinter
- importas
- ineffassign
- misspell
- nakedret
- nosprintfhostport
- nilerr
- noctx
- nolintlint
- nosprintfhostport
- prealloc
- promlinter
- revive
- sloglint
- sqlclosecheck
- staticcheck
- stylecheck
- testifylint
- tparallel
- thelper
- typecheck
- tparallel
- unconvert
- unparam
- unused
- usestdlibvars
- whitespace
- wrapcheck
- sqlclosecheck
- promlinter
- prealloc
- contextcheck

linters-settings:
gocritic:
disabled-checks: [captLocal]
revive:
rules:
- name: blank-imports
disabled: true
issues: {}
run:
timeout: 5m
settings:
gocritic:
disabled-checks:
- captLocal
revive:
rules:
- name: blank-imports
disabled: true
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofmt
- goimports
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
26 changes: 13 additions & 13 deletions cmd/watcher/app/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,20 @@ func loadConfig() {

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

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

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

<-ctx.Done()
logger.Info("shutting down")
logger.InfoContext(ctx, "shutting down")

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

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

eg.Go(func() error {
logger.Info(
logger.InfoContext(context.Background(),
"starting http server",
slog.String("component", "http-server"),
slog.String("addr", fmt.Sprintf("%s:%d", cfg.HTTP.Host, cfg.HTTP.Port)),
Expand All @@ -306,7 +306,7 @@ func startStatusWatcher(
) {
eg.Go(func() error {
statusWatcher := watcher.NewStatusWatcher(blockfrost, cardano, metrics, healthStore)
logger.Info(
logger.InfoContext(ctx,
"starting watcher",
slog.String("component", "status-watcher"),
)
Expand All @@ -331,7 +331,7 @@ func startPoolWatcher(
RefreshInterval: time.Second * time.Duration(cfg.PoolWatcherConfig.RefreshInterval),
Network: cfg.Network,
}
logger.Info(
logger.InfoContext(ctx,
"starting watcher",
slog.String("component", "pool-watcher"),
)
Expand Down Expand Up @@ -359,7 +359,7 @@ func startNetworkWatcher(
RefreshInterval: time.Second * time.Duration(cfg.PoolWatcherConfig.RefreshInterval),
Network: cfg.Network,
}
logger.Info(
logger.InfoContext(ctx,
"starting watcher",
slog.String("component", "network-watcher"),
)
Expand Down Expand Up @@ -388,7 +388,7 @@ func startBlockWatcher(
RefreshInterval: time.Second * time.Duration(cfg.BlockWatcherConfig.RefreshInterval),
}
blockWatcher := watcher.NewBlockWatcher(cardano, blockfrost, sl, pools, metrics, db, healthStore, options)
logger.Info(
logger.InfoContext(ctx,
"starting watcher",
slog.String("component", "block-watcher"),
)
Expand All @@ -403,7 +403,7 @@ func startBlockWatcher(
// used for the flag parsing
func checkError(err error, msg string) {
if err != nil {
logger.Error(msg, slog.String("error", err.Error()))
logger.ErrorContext(context.Background(), msg, slog.String("error", err.Error()))
os.Exit(1)
}
}
3 changes: 2 additions & 1 deletion cmd/watcher/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"log/slog"
"os"

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

command := app.NewWatcherCommand()
if err := command.Execute(); err != nil {
logger.Error("command execution failed", slog.String("error", err.Error()))
logger.ErrorContext(context.Background(), "command execution failed", slog.String("error", err.Error()))
os.Exit(1)
}
}
4 changes: 2 additions & 2 deletions internal/cardano/cardanocli/cardano.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (c *Client) Ping(ctx context.Context) error {
}

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

_, err := c.executor.ExecCommand(ctx, nil, "cardano-cli", args...)
if err != nil {
Expand Down Expand Up @@ -173,7 +173,7 @@ func (c *Client) LeaderLogs(ctx context.Context, ledgetSet string, epochNonce st
}
output, err := c.executor.ExecCommand(ctx, envs, "cncli", args...)
if err != nil {
c.logger.Error(
c.logger.ErrorContext(ctx,
fmt.Sprintf("unable to execute cncli leaderlog command: %v", err),
slog.String("pool_name", pool.Name),
slog.String("pool_id", pool.ID),
Expand Down
2 changes: 1 addition & 1 deletion internal/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (db *database) Connect(ctx context.Context) error {
if err != nil {
return fmt.Errorf("failed to connect to database: %w", err)
}
db.DB.SetMaxOpenConns(db.opts.MaxOpenConns)
db.SetMaxOpenConns(db.opts.MaxOpenConns)

return nil
}
Expand Down
6 changes: 3 additions & 3 deletions internal/slotleader/slotleader.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ func (s *Service) Refresh(ctx context.Context, epoch bfAPI.Epoch) error {
}

if !refreshed {
s.logger.Info(
s.logger.InfoContext(ctx,
fmt.Sprintf("⏰ refreshing slots for pool: %s", pool.Name),
slog.String("pool_id", pool.ID),
)
if err := s.cardano.LeaderLogs(ctx, "current", epochParams.Nonce, pool); err != nil {
return &ErrSlotLeaderRefresh{PoolID: pool.ID, Epoch: epoch.Epoch, Message: err.Error()}
}
} else {
s.logger.Info(
s.logger.InfoContext(ctx,
fmt.Sprintf("💠 slots already refreshed for pool: %s", pool.Name),
slog.String("pool_id", pool.ID),
)
Expand Down Expand Up @@ -105,7 +105,7 @@ func (s *Service) GetNextSlotLeader(ctx context.Context, PoolID string, height i
}

lastSlot := schedule.Slots[len(schedule.Slots)-1]
s.logger.Debug(
s.logger.DebugContext(ctx,
fmt.Sprintf("last slot for pool %s is %d", PoolID, lastSlot),
slog.String("pool_id", PoolID),
slog.Int("last_slot", lastSlot),
Expand Down
Loading
Loading