Skip to content
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
92 changes: 39 additions & 53 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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$
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# build stage
# =============================================================================

FROM golang:1.24.2-alpine AS builder
FROM golang:1.25.0-alpine AS builder

WORKDIR /sdk

Expand Down Expand Up @@ -33,15 +33,15 @@ 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
# =============================================================================

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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/configuration/builder/viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}

}
Expand Down
2 changes: 1 addition & 1 deletion pkg/context/database/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/context/logger/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/context/metrics/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/context/requestid/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/context/requestid/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion pkg/database/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/instrumentation/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions pkg/instrumentation/kafka/kafka_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/logger/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pkg/middleware/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand All @@ -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"])
Expand Down Expand Up @@ -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"])
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/tracking/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down