diff --git a/.golangci.yml b/.golangci.yml index 54438a7b..48accec0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,63 +1,49 @@ +version: "2" run: - # timeout for analysis, e.g. 30s, 5m, default is 1m - timeout: 2m - - # by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules": - # If invoked with -mod=readonly, the go command is disallowed from the implicit - # automatic updating of go.mod described above. Instead, it fails when any changes - # to go.mod are needed. This setting is most useful to check that go.mod does - # not need updates, such as in a continuous integration and testing system. - # If invoked with -mod=vendor, the go command assumes that the vendor - # directory holds the correct copies of dependencies and ignores - # the dependency descriptions in go.mod. modules-download-mode: readonly - linters: enable: - bodyclose - - errcheck - goconst - - gofmt - - gosimple - - govet - - ineffassign - lll - misspell - - staticcheck - - typecheck - unconvert - unparam - - unused - -linters-settings: - errcheck: - # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`; - # default is false: such cases aren't reported by default. - check-blank: true - govet: - enable: - - shadow - lll: - line-length: 120 - misspell: - locale: US - unused: - check-exported: false - unparam: - check-exported: false - -issues: - # Which dirs to exclude: issues from them won't be reported. - # Can use regexp here: `generated.*`, regexp is applied on full path, - # including the path prefix if one is set. - # Default dirs are skipped independently of this option's value (see exclude-dirs-use-default). - # "/" will be replaced by current OS file path separator to properly work on Windows. - # Default: [] - exclude-dirs: - - configs - exclude-rules: - # SA1029 – Inappropriate key in call to context.WithValue - # https://staticcheck.io/docs/checks#SA1029 - - linters: - - staticcheck - text: "SA1029:" + settings: + errcheck: + check-blank: true + govet: + enable: + - shadow + lll: + line-length: 120 + misspell: + locale: US + unparam: + check-exported: false + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + rules: + - linters: + - staticcheck + text: 'SA1029:' + paths: + - configs + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + exclusions: + generated: lax + paths: + - configs + - third_party$ + - builtin$ + - examples$ diff --git a/Dockerfile b/Dockerfile index 63de4885..66db9c44 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ # build stage # ============================================================================= -FROM golang:1.24.2-alpine AS builder +FROM golang:1.25.0-alpine AS builder WORKDIR /sdk @@ -33,10 +33,10 @@ FROM builder AS linter # binary will be $(go env GOPATH)/bin/golangci-lint RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh \ - | sh -s -- -b $(go env GOPATH)/bin v1.64.8 + | sh -s -- -b $(go env GOPATH)/bin v2.4.0 # install goimports -RUN go install golang.org/x/tools/cmd/goimports@v0.32.0 +RUN go install golang.org/x/tools/cmd/goimports@v0.36.0 # ============================================================================= # development stage @@ -44,4 +44,4 @@ RUN go install golang.org/x/tools/cmd/goimports@v0.32.0 FROM linter AS development -RUN go install github.com/go-delve/delve/cmd/dlv@v1.24.2 +RUN go install github.com/go-delve/delve/cmd/dlv@v1.25.1 diff --git a/README.md b/README.md index ccb10b07..18f9c5bd 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ SDK, the Go version. ## Prerequisites -* [Go](https://golang.org) (version `1.24.0`). +* [Go](https://golang.org) (version `1.25.0`). * [Docker](https://www.docker.com/) (version `19.03.2`). ## SDK functionality @@ -1736,7 +1736,7 @@ You can enter the docker environment to build, run and debug your service: ``` $ docker-compose run --rm sdk /bin/bash root@1f31fa8e5c49:/sdk# go version -go version go1.24.0 linux/amd64 +go version go1.25.0 linux/amd64 ``` Refer to the diff --git a/go.mod b/go.mod index 59eb8d2e..e1ab81ad 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,6 @@ module github.com/scribd/go-sdk -go 1.24.0 - -toolchain go1.24.2 +go 1.25.0 require ( github.com/DATA-DOG/go-sqlmock v1.5.2 diff --git a/internal/pkg/configuration/builder/viper.go b/internal/pkg/configuration/builder/viper.go index 8ab05880..fc3cfe65 100644 --- a/internal/pkg/configuration/builder/viper.go +++ b/internal/pkg/configuration/builder/viper.go @@ -65,7 +65,7 @@ func (vb *ViperBuilder) Build() (*viper.Viper, error) { env := vb.vConf.GetString("ENV") vb.vConf = vb.vConf.Sub(env) if vb.vConf == nil { - return nil, fmt.Errorf("No %s configuration for ENV %s", vb.name, env) + return nil, fmt.Errorf("no %s configuration for ENV %s", vb.name, env) } vb.vConf.Set("ENV", env) @@ -76,7 +76,7 @@ func (vb *ViperBuilder) Build() (*viper.Viper, error) { allKeys := vb.vConf.AllKeys() for _, k := range allKeys { if err := vb.vConf.BindEnv(strings.ToUpper(k)); err != nil { - return nil, fmt.Errorf("Could not configure %s for ENV %s", k, env) + return nil, fmt.Errorf("could not configure %s for ENV %s", k, env) } } diff --git a/pkg/context/database/context.go b/pkg/context/database/context.go index 5cf13947..d0bd8e17 100644 --- a/pkg/context/database/context.go +++ b/pkg/context/database/context.go @@ -22,7 +22,7 @@ var ( func Extract(ctx context.Context) (*gorm.DB, error) { d, ok := ctx.Value(ctxDatabaseKey).(*ctxDatabase) if !ok || d == nil { - return nil, fmt.Errorf("Unable to get the database") + return nil, fmt.Errorf("unable to get the database") } return d.database, nil diff --git a/pkg/context/logger/context.go b/pkg/context/logger/context.go index af3bf080..dc9e47c8 100644 --- a/pkg/context/logger/context.go +++ b/pkg/context/logger/context.go @@ -36,7 +36,7 @@ func AddFields(ctx context.Context, fields sdklogger.Fields) { func Extract(ctx context.Context) (sdklogger.Logger, error) { l, ok := ctx.Value(ctxLoggerKey).(*ctxLogger) if !ok || l == nil { - return nil, fmt.Errorf("Unable to get the logger") + return nil, fmt.Errorf("unable to get the logger") } fields := sdklogger.Fields{} diff --git a/pkg/context/metrics/context.go b/pkg/context/metrics/context.go index dbce3997..25c53b9d 100644 --- a/pkg/context/metrics/context.go +++ b/pkg/context/metrics/context.go @@ -22,7 +22,7 @@ var ( func Extract(ctx context.Context) (sdkmetrics.Metrics, error) { m, ok := ctx.Value(ctxMetricsKey).(*ctxMetrics) if !ok || m == nil { - return nil, fmt.Errorf("Unable to get the metrics") + return nil, fmt.Errorf("unable to get the metrics") } return m.metrics, nil diff --git a/pkg/context/requestid/context.go b/pkg/context/requestid/context.go index 1f053c5d..d0b815cb 100644 --- a/pkg/context/requestid/context.go +++ b/pkg/context/requestid/context.go @@ -20,7 +20,7 @@ var ( func Extract(ctx context.Context) (string, error) { r, ok := ctx.Value(ctxRequestIDKey).(*ctxRequestID) if !ok || r == nil { - return "", fmt.Errorf("Unable to get the requestID") + return "", fmt.Errorf("unable to get the requestID") } return r.requestID, nil diff --git a/pkg/context/requestid/context_test.go b/pkg/context/requestid/context_test.go index 35800be3..51ab6d64 100644 --- a/pkg/context/requestid/context_test.go +++ b/pkg/context/requestid/context_test.go @@ -20,7 +20,7 @@ func TestExtract(t *testing.T) { ctxSet: func(ctx context.Context) context.Context { return ctx }, - expectedError: fmt.Errorf("Unable to get the requestID"), + expectedError: fmt.Errorf("unable to get the requestID"), }, { name: "Context contains request id", diff --git a/pkg/database/config.go b/pkg/database/config.go index 28516a7e..a88ccdec 100644 --- a/pkg/database/config.go +++ b/pkg/database/config.go @@ -39,7 +39,7 @@ func NewConfig() (*Config, error) { } if err = vConf.Unmarshal(config); err != nil { - return config, fmt.Errorf("Unable to decode into struct: %s", err.Error()) + return config, fmt.Errorf("unable to decode into struct: %s", err.Error()) } return config, nil diff --git a/pkg/instrumentation/config.go b/pkg/instrumentation/config.go index 9a34882f..329a6e36 100644 --- a/pkg/instrumentation/config.go +++ b/pkg/instrumentation/config.go @@ -29,7 +29,7 @@ func NewConfig() (*Config, error) { } if err = vConf.Unmarshal(config); err != nil { - return config, fmt.Errorf("Unable to decode into struct: %s", err.Error()) + return config, fmt.Errorf("unable to decode into struct: %s", err.Error()) } config.environment = vConf.GetString("ENV") diff --git a/pkg/instrumentation/kafka/kafka_test.go b/pkg/instrumentation/kafka/kafka_test.go index cf261d46..58e287c5 100644 --- a/pkg/instrumentation/kafka/kafka_test.go +++ b/pkg/instrumentation/kafka/kafka_test.go @@ -83,7 +83,7 @@ func TestNewClient(t *testing.T) { c.Produce(ctx, &kgo.Record{Topic: "test"}, nil) - fetches := c.KafkaClient.PollRecords(context.Background(), 1) + fetches := c.PollRecords(context.Background(), 1) iter := c.WrapFetchesRecordIter(ctx, fetches.RecordIter()) for !iter.Done() { @@ -98,7 +98,7 @@ func TestNewClient(t *testing.T) { c.Produce(ctx, &kgo.Record{Topic: "test"}, nil) - fetches := c.KafkaClient.PollRecords(context.Background(), 1) + fetches := c.PollRecords(context.Background(), 1) fetches.EachTopic(func(ft kgo.FetchTopic) { ft.EachPartition(func(fp kgo.FetchPartition) { wfp := c.WrapFetchPartition(ctx, fp) diff --git a/pkg/logger/config.go b/pkg/logger/config.go index 8fbbd78c..7125502a 100644 --- a/pkg/logger/config.go +++ b/pkg/logger/config.go @@ -36,7 +36,7 @@ func NewConfig() (*Config, error) { } if err = vConf.Unmarshal(config); err != nil { - return config, fmt.Errorf("Unable to decode into struct: %s", err.Error()) + return config, fmt.Errorf("unable to decode into struct: %s", err.Error()) } return config, nil diff --git a/pkg/middleware/logger_test.go b/pkg/middleware/logger_test.go index 4aed8f26..b31f4574 100644 --- a/pkg/middleware/logger_test.go +++ b/pkg/middleware/logger_test.go @@ -73,7 +73,7 @@ func TestOutputStructuredContentFromMiddleware(t *testing.T) { assert.NotEmpty(t, fields["timestamp"]) assert.NotEmpty(t, fields["http"]) - var http map[string]interface{} = (fields["http"]).(map[string]interface{}) + var http = (fields["http"]).(map[string]interface{}) assert.NotNil(t, http["remote_addr"]) assert.NotNil(t, http["request_id"]) @@ -86,7 +86,7 @@ func TestOutputStructuredContentFromMiddleware(t *testing.T) { assert.NotEmpty(t, http["response_status"]) assert.NotNil(t, http["response_time_total_ms"]) - var dd map[string]interface{} = (fields["dd"]).(map[string]interface{}) + var dd = (fields["dd"]).(map[string]interface{}) assert.NotNil(t, dd["trace_id"]) assert.NotNil(t, dd["span_id"]) @@ -132,7 +132,7 @@ func TestResponseStatusFromMiddleware(t *testing.T) { require.Nil(t, err) assertions := func(fields map[string]interface{}) { - var http map[string]interface{} = (fields["http"]).(map[string]interface{}) + var http = (fields["http"]).(map[string]interface{}) assert.EqualValues(t, 400, http["response_status"]) } diff --git a/pkg/server/config.go b/pkg/server/config.go index e53ad89b..c140b116 100644 --- a/pkg/server/config.go +++ b/pkg/server/config.go @@ -95,7 +95,7 @@ func NewConfig() (*Config, error) { } if err = vConf.Unmarshal(config); err != nil { - return config, fmt.Errorf("Unable to decode into struct: %s", err.Error()) + return config, fmt.Errorf("unable to decode into struct: %s", err.Error()) } return config, nil diff --git a/pkg/tracking/config.go b/pkg/tracking/config.go index b418e445..0949a036 100644 --- a/pkg/tracking/config.go +++ b/pkg/tracking/config.go @@ -31,7 +31,7 @@ func NewConfig() (*Config, error) { } if err = vConf.Unmarshal(config); err != nil { - return config, fmt.Errorf("Unable to decode into struct: %s", err.Error()) + return config, fmt.Errorf("unable to decode into struct: %s", err.Error()) } return config, nil