diff --git a/.buildkite/pipeline.yaml b/.buildkite/pipeline.yaml index 0d02852..2db2a61 100644 --- a/.buildkite/pipeline.yaml +++ b/.buildkite/pipeline.yaml @@ -11,16 +11,7 @@ steps: plugins: - docker#v5.13.0: image: "registry.hub.docker.com/golangci/golangci-lint:v2.4.0" - command: - [ - "golangci-lint", - "run", - "-v", - "--config", - ".golangci.yaml", - "--concurrency", - "0", - ] + command: ["golangci-lint", "run", "-v", "--config", ".golangci.yaml", "--concurrency", "0"] environment: - "GOTOOLCHAIN=auto" - label: ":golang: go test" @@ -28,7 +19,7 @@ steps: cancel_on_build_failing: true plugins: - docker#v5.13.0: - image: golang:1.25.1 + image: golang:1.25.4 always-pull: true command: ["go", "test", "-coverprofile=coverage.out", "./..."] artifact_paths: ["coverage.out"] diff --git a/.golangci.yaml b/.golangci.yaml index b7395ad..2d36e7e 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -14,7 +14,12 @@ linters: - revive - staticcheck - whitespace - - wsl + - wsl_v5 + settings: + wsl_v5: + allow-first-in-block: true + allow-whole-block: false + branch-max-lines: 2 exclusions: generated: lax presets: diff --git a/cache/client.go b/cache/client.go index b849e0d..73f34aa 100644 --- a/cache/client.go +++ b/cache/client.go @@ -22,31 +22,31 @@ type Config struct { // DB to be selected after connecting to the server, 0 uses the default DB int `json:"db" koanf:"db" default:"0"` // Dial timeout for establishing new connections, defaults to 5s - DialTimeout time.Duration `json:"dialTimeout" koanf:"dialTimeout" default:"5s"` + DialTimeout time.Duration `json:"dialtimeout" koanf:"dialtimeout" default:"5s"` // Timeout for socket reads. If reached, commands will fail // with a timeout instead of blocking. Supported values: // - `0` - default timeout (3 seconds). // - `-1` - no timeout (block indefinitely). // - `-2` - disables SetReadDeadline calls completely. - ReadTimeout time.Duration `json:"readTimeout" koanf:"readTimeout" default:"0"` + ReadTimeout time.Duration `json:"readtimeout" koanf:"readtimeout" default:"0"` // Timeout for socket writes. If reached, commands will fail // with a timeout instead of blocking. Supported values: // - `0` - default timeout (3 seconds). // - `-1` - no timeout (block indefinitely). // - `-2` - disables SetWriteDeadline calls completely. - WriteTimeout time.Duration `json:"writeTimeout" koanf:"writeTimeout" default:"0"` + WriteTimeout time.Duration `json:"writetimeout" koanf:"writetimeout" default:"0"` // MaxRetries before giving up. // Default is 3 retries; -1 (not 0) disables retries. - MaxRetries int `json:"maxRetries" koanf:"maxRetries" default:"3"` + MaxRetries int `json:"maxretries" koanf:"maxretries" default:"3"` // MinIdleConns is useful when establishing new connection is slow. // Default is 0. the idle connections are not closed by default. - MinIdleConns int `json:"minIdleConns" koanf:"minIdleConns" default:"0"` + MinIdleConns int `json:"minidleconns" koanf:"minidleconns" default:"0"` // Maximum number of idle connections. // Default is 0. the idle connections are not closed by default. - MaxIdleConns int `json:"maxIdleConns" koanf:"maxIdleConns" default:"0"` + MaxIdleConns int `json:"maxidleconns" koanf:"maxidleconns" default:"0"` // Maximum number of connections allocated by the pool at a given time. // When zero, there is no limit on the number of connections in the pool. - MaxActiveConns int `json:"maxActiveConns" koanf:"maxActiveConns" default:"0"` + MaxActiveConns int `json:"maxactiveconns" koanf:"maxactiveconns" default:"0"` } // New returns a new redis client based on the configuration settings diff --git a/contextx/contextx_test.go b/contextx/contextx_test.go index 7609a27..9367131 100644 --- a/contextx/contextx_test.go +++ b/contextx/contextx_test.go @@ -103,6 +103,7 @@ func TestFromOrFunc(t *testing.T) { func TestStringHelpers(t *testing.T) { type OrganizationID string + type TraceID string ctx := context.Background() diff --git a/go.mod b/go.mod index b53adb0..29987ac 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/theopenlane/utils -go 1.25.1 +go 1.25.4 require ( entgo.io/ent v0.14.5 @@ -16,6 +16,8 @@ require ( golang.org/x/crypto v0.42.0 ) +require github.com/opencontainers/runc v1.2.8 // indirect + require ( al.essio.dev/pkg/shellescape v1.5.1 // indirect github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect @@ -37,11 +39,11 @@ require ( github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.16 // indirect + github.com/moby/sys/user v0.3.0 // indirect github.com/olekukonko/errors v1.1.0 // indirect github.com/olekukonko/ll v0.0.9 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect github.com/opencontainers/image-spec v1.1.0 // indirect - github.com/opencontainers/runc v1.1.14 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/rivo/uniseg v0.4.7 // indirect diff --git a/go.sum b/go.sum index f605d83..70f7ab5 100644 --- a/go.sum +++ b/go.sum @@ -53,6 +53,8 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/moby/sys/user v0.3.0 h1:9ni5DlcW5an3SvRSx4MouotOygvzaXbaSrc/wGDFWPo= +github.com/moby/sys/user v0.3.0/go.mod h1:bG+tYYYJgaMtRKgEmuueC0hJEAZWwtIbZTB+85uoHjs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/oklog/ulid/v2 v2.1.1 h1:suPZ4ARWLOJLegGFiZZ1dFAkqzhMjL3J1TzI+5wHz8s= @@ -67,8 +69,8 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8 github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug= github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM= -github.com/opencontainers/runc v1.1.14 h1:rgSuzbmgz5DUJjeSnw337TxDbRuqjs6iqQck/2weR6w= -github.com/opencontainers/runc v1.1.14/go.mod h1:E4C2z+7BxR7GHXp0hAY53mek+x49X1LjPNeMTfRGvOA= +github.com/opencontainers/runc v1.2.8 h1:RnEICeDReapbZ5lZEgHvj7E9Q3Eex9toYmaGBsbvU5Q= +github.com/opencontainers/runc v1.2.8/go.mod h1:cC0YkmZcuvr+rtBZ6T7NBoVbMGNAdLa/21vIElJDOzI= github.com/ory/dockertest v3.3.5+incompatible h1:iLLK6SQwIhcbrG783Dghaaa3WPzGc+4Emza6EbVUUGA= github.com/ory/dockertest v3.3.5+incompatible/go.mod h1:1vX4m9wsvi00u5bseYwXaSnhNrne+V0E6LAcBILJdPs= github.com/pborman/getopt v0.0.0-20170112200414-7148bc3a4c30/go.mod h1:85jBQOZwpVEaDAr341tbn15RS4fCAsIst0qp7i8ex1o= diff --git a/rout/errors.go b/rout/errors.go index 96a3224..90e1988 100644 --- a/rout/errors.go +++ b/rout/errors.go @@ -206,6 +206,7 @@ func ErrorResponse(err interface{}) Reply { } rep := Reply{Success: false} + switch err := err.(type) { case error: rep.Error = err.Error() @@ -249,6 +250,7 @@ func HTTPErrorResponse(err interface{}) *echo.HTTPError { } rep := echo.HTTPError{Code: http.StatusBadRequest} + switch err := err.(type) { case error: rep.Message = err.Error() diff --git a/ulids/ulids.go b/ulids/ulids.go index 631aece..836c6c4 100644 --- a/ulids/ulids.go +++ b/ulids/ulids.go @@ -40,8 +40,8 @@ func IsZero(uid ulid.ULID) bool { // this method panics rather than returning an error func New() ulid.ULID { ms := ulid.Timestamp(time.Now()) - uid, err := ulid.New(ms, entropy) + uid, err := ulid.New(ms, entropy) if err != nil { panic(err) } @@ -52,8 +52,8 @@ func New() ulid.ULID { // FromTime creates a ULID with the specified timestamp func FromTime(ts time.Time) ulid.ULID { ms := ulid.Timestamp(ts) - uid, err := ulid.New(ms, entropy) + uid, err := ulid.New(ms, entropy) if err != nil { panic(err) }