Fix every finding surfaced by the canonical .golangci.yml with golangci-lint v2.12.2 (refs #61), behavior-preserving throughout: - err113: dynamic errors replaced with package-level sentinels and %w wrapping; direct comparisons converted to errors.Is - goprintffuncname: printf-style helpers renamed with an f suffix (ui.Writer message methods, cli.ReportErrorf, database.Fatalf, vaultik stdoutf) and all call sites updated - revive: stuttering type names renamed (blob.Handler, blob.WithReader, blob.ChunkPosition, storage.URL, storage.Info), doc comments added, unused parameters blanked, package comments added - contextcheck/noctx: ctx threaded through blob.Packer (AddChunk/Flush/FinalizeBlob/PackChunks) and scanner call sites; context-aware exec and sql variants used - funlen/cyclop/gocognit/nestif/dupl: oversized or duplicated functions split into focused helpers across production and test code - paralleltest/tparallel/thelper/usetesting/testpackage: tests parallelized where safe (global log.Initialize kept in the serial phase), helpers marked, t.TempDir adopted, external test packages where only exported API is used - gosec: integer conversions clamped or justified, header timeouts added, remaining findings suppressed with per-site justifications - mnd/goconst/lll/wsl_v5/nlreturn/noinlineerr/errcheck and other mechanical findings fixed directly Remove the deprecated log.LogOptions alias (callers migrated to log.Options). make check is green.
45 lines
984 B
Go
45 lines
984 B
Go
package s3
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.uber.org/fx"
|
|
"sneak.berlin/go/vaultik/internal/config"
|
|
)
|
|
|
|
// Module exports S3 functionality as an fx module.
|
|
// It provides automatic dependency injection for the S3 client,
|
|
// configuring it based on the application's configuration settings.
|
|
//
|
|
//nolint:gochecknoglobals // fx module definitions are package globals
|
|
var Module = fx.Module("s3",
|
|
fx.Provide(
|
|
provideClient,
|
|
),
|
|
)
|
|
|
|
func provideClient(lc fx.Lifecycle, cfg *config.Config) (*Client, error) {
|
|
ctx := context.Background()
|
|
|
|
client, err := NewClient(ctx, Config{
|
|
Endpoint: cfg.S3.Endpoint,
|
|
Bucket: cfg.S3.Bucket,
|
|
Prefix: cfg.S3.Prefix,
|
|
AccessKeyID: cfg.S3.AccessKeyID,
|
|
SecretAccessKey: cfg.S3.SecretAccessKey,
|
|
Region: cfg.S3.Region,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
lc.Append(fx.Hook{
|
|
OnStop: func(_ context.Context) error {
|
|
// S3 client doesn't need explicit cleanup
|
|
return nil
|
|
},
|
|
})
|
|
|
|
return client, nil
|
|
}
|