diff --git a/buildutil b/buildutil index b52809a..3f1b5f2 100755 --- a/buildutil +++ b/buildutil @@ -1,5 +1,5 @@ #!/usr/bin/env sh set -eu -go mod vendor +test -z "$(go env GOWORK)" && go mod vendor || go work vendor go generate ./... exec go run ./cmd/buildutil "$@" diff --git a/cmd/buildutil/chain.go b/cmd/buildutil/chain.go index 470c73f..c5534fb 100644 --- a/cmd/buildutil/chain.go +++ b/cmd/buildutil/chain.go @@ -8,7 +8,7 @@ import ( "strconv" "strings" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/executil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/executil" ) type ChainExecutor struct { diff --git a/cmd/buildutil/info.go b/cmd/buildutil/info.go index c2488ec..79020da 100644 --- a/cmd/buildutil/info.go +++ b/cmd/buildutil/info.go @@ -13,7 +13,7 @@ import ( "time" "github.com/pkg/errors" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/cmdutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/cmdutil" "github.com/sirupsen/logrus" "golang.org/x/mod/modfile" "golang.org/x/tools/go/packages" @@ -153,6 +153,7 @@ type BuildInfo struct { Module string Dir string Version string + Work string } Commit struct { @@ -255,6 +256,7 @@ func CollectBuildInformation(ctx context.Context, p BuildParameters) (BuildInfo, info.Commit.Date = time.Unix(e.OutputInt64("git", "show", "-s", "--format=%ct"), 0).Format(time.RFC3339) info.Commit.Hash = e.OutputString("git", "rev-parse", "HEAD") info.Commit.Branch = e.OutputString("git", "rev-parse", "--abbrev-ref", "HEAD") + info.Go.Work = e.OutputString(p.GoCommand, "env", "GOWORK") info.SDKVersion, err = ParseVersion(e.OutputString(p.GoCommand, "list", "-mod=readonly", "-m", "-f", "{{.Version}}", "github.com/rebuy-de/rebuy-go-sdk/...")) if err != nil { @@ -287,7 +289,9 @@ func CollectBuildInformation(ctx context.Context, p BuildParameters) (BuildInfo, info.Go.Name = nameMatch[1] } - cmdutil.Must(e.Err()) + if e.Err() != nil { + return info, e.Err() + } targetSystems := []SystemInfo{} for _, target := range p.TargetSystems { @@ -322,7 +326,9 @@ func CollectBuildInformation(ctx context.Context, p BuildParameters) (BuildInfo, pkgs, err := packages.Load(&packages.Config{ Context: ctx, }, search) - cmdutil.Must(err) + if err != nil { + return info, err + } for _, pkg := range pkgs { if pkg.Name != "main" { @@ -352,7 +358,9 @@ func CollectBuildInformation(ctx context.Context, p BuildParameters) (BuildInfo, } testPackages, err := packages.Load(nil, "./...") - cmdutil.Must(err) + if err != nil { + return info, err + } info.Test.Packages = []string{} info.Test.Files = []string{} diff --git a/cmd/buildutil/instrumentation.go b/cmd/buildutil/instrumentation.go index 39c1d20..b59a6d2 100644 --- a/cmd/buildutil/instrumentation.go +++ b/cmd/buildutil/instrumentation.go @@ -7,7 +7,7 @@ import ( "sync" "time" - "github.com/rebuy-de/rebuy-go-sdk/v7/cmd/buildutil/internal/typeutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/cmd/buildutil/internal/typeutil" "github.com/sirupsen/logrus" ) diff --git a/cmd/buildutil/logutil.go b/cmd/buildutil/logutil.go index fde45d8..3aed829 100644 --- a/cmd/buildutil/logutil.go +++ b/cmd/buildutil/logutil.go @@ -5,7 +5,7 @@ import ( "fmt" "os" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/cmdutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/cmdutil" "github.com/tidwall/pretty" ) diff --git a/cmd/buildutil/main.go b/cmd/buildutil/main.go index 09f0a6a..dbe251b 100644 --- a/cmd/buildutil/main.go +++ b/cmd/buildutil/main.go @@ -6,7 +6,7 @@ import ( "github.com/sirupsen/logrus" "github.com/spf13/cobra" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/cmdutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/cmdutil" ) func main() { diff --git a/cmd/buildutil/runner.go b/cmd/buildutil/runner.go index 2742007..7c21c09 100644 --- a/cmd/buildutil/runner.go +++ b/cmd/buildutil/runner.go @@ -24,8 +24,8 @@ import ( "github.com/sirupsen/logrus" "github.com/spf13/cobra" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/cmdutil" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/executil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/cmdutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/executil" ) func call(ctx context.Context, command string, args ...string) { @@ -139,13 +139,18 @@ func (r *Runner) RunClean(ctx context.Context, cmd *cobra.Command, args []string func (r *Runner) RunVendor(ctx context.Context, cmd *cobra.Command, args []string) { defer r.Inst.Durations.Steps.Stopwatch("vendor")() - call(ctx, r.Parameters.GoCommand, "mod", "vendor") + if r.Info.Go.Work == "" { + call(ctx, r.Parameters.GoCommand, "mod", "vendor") + } else { + call(ctx, r.Parameters.GoCommand, "work", "vendor") + } } func (r *Runner) RunTest(ctx context.Context, cmd *cobra.Command, args []string) { defer r.Inst.Durations.Steps.Stopwatch("test")() r.RunTestFormat(ctx, cmd, args) + r.RunTestStaticcheck(ctx, cmd, args) r.RunTestVet(ctx, cmd, args) r.RunTestPackages(ctx, cmd, args) } @@ -159,6 +164,22 @@ func (r *Runner) RunTestFormat(ctx context.Context, cmd *cobra.Command, args []s call(ctx, "gofmt", a...) } +func (r *Runner) RunTestStaticcheck(ctx context.Context, cmd *cobra.Command, args []string) { + fail := []string{ + "all", + "-SA1019", // Using a deprecated function, variable, constant or field + } + + logrus.Info("Testing staticcheck") + defer r.Inst.Durations.Testing.Stopwatch("staticcheck")() + call(ctx, r.Parameters.GoCommand, + "run", "honnef.co/go/tools/cmd/staticcheck", + "-f", "stylish", + "-fail", strings.Join(fail, ","), + "./...", + ) +} + func (r *Runner) RunTestVet(ctx context.Context, cmd *cobra.Command, args []string) { a := []string{"vet"} a = append(a, r.Info.Test.Packages...) @@ -201,7 +222,7 @@ func (r *Runner) RunBuild(ctx context.Context, cmd *cobra.Command, args []string ldFlags := []string{} for _, entry := range ldData { ldFlags = append(ldFlags, fmt.Sprintf( - `-X 'github.com/rebuy-de/rebuy-go-sdk/v7/pkg/cmdutil.%s=%s'`, + `-X 'github.com/rebuy-de/rebuy-go-sdk/v8/pkg/cmdutil.%s=%s'`, entry.name, entry.value, )) } diff --git a/cmd/cdnmirror/main.go b/cmd/cdnmirror/main.go index 0673b79..10d98d3 100644 --- a/cmd/cdnmirror/main.go +++ b/cmd/cdnmirror/main.go @@ -13,7 +13,7 @@ import ( "github.com/evanw/esbuild/pkg/api" "github.com/pkg/errors" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/cmdutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/cmdutil" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/examples/full/buildutil b/examples/full/buildutil index de5f534..33c9156 100755 --- a/examples/full/buildutil +++ b/examples/full/buildutil @@ -2,4 +2,4 @@ set -eu go mod vendor go generate ./... -exec go run github.com/rebuy-de/rebuy-go-sdk/v7/cmd/buildutil "$@" +exec go run github.com/rebuy-de/rebuy-go-sdk/v8/cmd/buildutil "$@" diff --git a/examples/full/cmd/inst.go b/examples/full/cmd/inst.go index ce717ca..6f90851 100644 --- a/examples/full/cmd/inst.go +++ b/examples/full/cmd/inst.go @@ -5,8 +5,8 @@ import ( "net/http" "strings" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/instutil" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/logutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/instutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/logutil" ) // inst.go contains all functions for handling instrumentation (ie metrics and diff --git a/examples/full/cmd/root.go b/examples/full/cmd/root.go index 2cbc8b2..63a2611 100644 --- a/examples/full/cmd/root.go +++ b/examples/full/cmd/root.go @@ -7,9 +7,9 @@ import ( "io/fs" "os" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/cmdutil" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/podutil" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/redisutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/cmdutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/podutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/redisutil" "github.com/redis/go-redis/v9" "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -90,7 +90,6 @@ func (r *DaemonRunner) Run(ctx context.Context) error { // DevRunner bootstraps the application for local development. It defines the // related flags and calls the actual server code. type DevRunner struct { - redisAddress string } // Bind implements the cmdutil.Runner interface and defines command line flags. diff --git a/examples/full/cmd/server.go b/examples/full/cmd/server.go index 297cd60..36aefe0 100644 --- a/examples/full/cmd/server.go +++ b/examples/full/cmd/server.go @@ -10,10 +10,10 @@ import ( "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" "github.com/pkg/errors" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/cmdutil" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/logutil" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/redisutil" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/webutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/cmdutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/logutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/redisutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/webutil" "github.com/redis/go-redis/v9" "golang.org/x/sync/errgroup" ) diff --git a/examples/full/go.mod b/examples/full/go.mod index d183423..e8ddd96 100644 --- a/examples/full/go.mod +++ b/examples/full/go.mod @@ -1,22 +1,24 @@ -module github.com/rebuy-de/rebuy-go-sdk/v7/examples/full +module github.com/rebuy-de/rebuy-go-sdk/v8/examples/full go 1.22.0 -replace github.com/rebuy-de/rebuy-go-sdk/v7 => ../.. +replace github.com/rebuy-de/rebuy-go-sdk/v8 => ../.. require ( github.com/go-chi/chi/v5 v5.0.12 github.com/pkg/errors v0.9.1 - github.com/rebuy-de/rebuy-go-sdk/v7 v7.0.0 + github.com/rebuy-de/rebuy-go-sdk/v8 v8.0.0 github.com/redis/go-redis/v9 v9.5.1 github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.8.0 golang.org/x/sync v0.6.0 + honnef.co/go/tools v0.4.7 ) require ( dario.cat/mergo v1.0.0 // indirect github.com/AlekSi/pointer v1.2.0 // indirect + github.com/BurntSushi/toml v1.2.1 // indirect github.com/Masterminds/goutils v1.1.1 // indirect github.com/Masterminds/semver/v3 v3.2.1 // indirect github.com/Masterminds/sprig/v3 v3.2.3 // indirect @@ -96,6 +98,7 @@ require ( gitlab.com/digitalxero/go-conventional-commit v1.0.7 // indirect golang.org/x/crypto v0.19.0 // indirect golang.org/x/exp v0.0.0-20240213143201-ec583247a57a // indirect + golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a // indirect golang.org/x/mod v0.15.0 // indirect golang.org/x/net v0.21.0 // indirect golang.org/x/oauth2 v0.17.0 // indirect diff --git a/examples/full/go.sum b/examples/full/go.sum index 00f7207..b0f4f2f 100644 --- a/examples/full/go.sum +++ b/examples/full/go.sum @@ -2,6 +2,8 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= github.com/AlekSi/pointer v1.2.0 h1:glcy/gc4h8HnG2Z3ZECSzZ1IX1x2JxRVuDzaJwQE0+w= github.com/AlekSi/pointer v1.2.0/go.mod h1:gZGfd3dpW4vEc/UlyfKKi1roIqcCgwOIvb0tSNSBle0= +github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak= +github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= @@ -266,6 +268,8 @@ golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/exp v0.0.0-20240213143201-ec583247a57a h1:HinSgX1tJRX3KsL//Gxynpw5CTOAIPhgL4W8PNiIpVE= golang.org/x/exp v0.0.0-20240213143201-ec583247a57a/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc= +golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a h1:Jw5wfR+h9mnIYH+OtGT2im5wV1YGGDora5vTv/aa5bE= +golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8= @@ -348,3 +352,5 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.4.7 h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs= +honnef.co/go/tools v0.4.7/go.mod h1:+rnGS1THNh8zMwnd2oVOTL9QF6vmfyG6ZXBULae2uc0= diff --git a/examples/full/main.go b/examples/full/main.go index eba1f7a..1a742d5 100644 --- a/examples/full/main.go +++ b/examples/full/main.go @@ -1,10 +1,10 @@ package main import ( - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/cmdutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/cmdutil" "github.com/sirupsen/logrus" - "github.com/rebuy-de/rebuy-go-sdk/v7/examples/full/cmd" + "github.com/rebuy-de/rebuy-go-sdk/v8/examples/full/cmd" ) func main() { diff --git a/examples/full/tools.go b/examples/full/tools.go index fe3dedf..693342e 100644 --- a/examples/full/tools.go +++ b/examples/full/tools.go @@ -5,5 +5,6 @@ package main // https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module import ( - _ "github.com/rebuy-de/rebuy-go-sdk/v7/cmd/buildutil" + _ "github.com/rebuy-de/rebuy-go-sdk/v8/cmd/buildutil" + _ "honnef.co/go/tools/cmd/staticcheck" ) diff --git a/examples/minimal/buildutil b/examples/minimal/buildutil index de5f534..33c9156 100755 --- a/examples/minimal/buildutil +++ b/examples/minimal/buildutil @@ -2,4 +2,4 @@ set -eu go mod vendor go generate ./... -exec go run github.com/rebuy-de/rebuy-go-sdk/v7/cmd/buildutil "$@" +exec go run github.com/rebuy-de/rebuy-go-sdk/v8/cmd/buildutil "$@" diff --git a/examples/minimal/cmd/root.go b/examples/minimal/cmd/root.go index 1fd16a6..d379c47 100644 --- a/examples/minimal/cmd/root.go +++ b/examples/minimal/cmd/root.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/cmdutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/cmdutil" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/examples/minimal/go.mod b/examples/minimal/go.mod index e8f0c48..162ac6b 100644 --- a/examples/minimal/go.mod +++ b/examples/minimal/go.mod @@ -1,18 +1,20 @@ -module github.com/rebuy-de/rebuy-go-sdk/v7/examples/minimal +module github.com/rebuy-de/rebuy-go-sdk/v8/examples/minimal go 1.22.0 -replace github.com/rebuy-de/rebuy-go-sdk/v7 => ../.. +replace github.com/rebuy-de/rebuy-go-sdk/v8 => ../.. require ( - github.com/rebuy-de/rebuy-go-sdk/v7 v7.0.0 + github.com/rebuy-de/rebuy-go-sdk/v8 v8.0.0 github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.8.0 + honnef.co/go/tools v0.4.7 ) require ( dario.cat/mergo v1.0.0 // indirect github.com/AlekSi/pointer v1.2.0 // indirect + github.com/BurntSushi/toml v1.2.1 // indirect github.com/Masterminds/goutils v1.1.1 // indirect github.com/Masterminds/semver/v3 v3.2.1 // indirect github.com/Masterminds/sprig/v3 v3.2.3 // indirect @@ -76,6 +78,7 @@ require ( gitlab.com/digitalxero/go-conventional-commit v1.0.7 // indirect golang.org/x/crypto v0.19.0 // indirect golang.org/x/exp v0.0.0-20240213143201-ec583247a57a // indirect + golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a // indirect golang.org/x/mod v0.15.0 // indirect golang.org/x/net v0.21.0 // indirect golang.org/x/sys v0.17.0 // indirect diff --git a/examples/minimal/go.sum b/examples/minimal/go.sum index 0c02242..8b6b6b6 100644 --- a/examples/minimal/go.sum +++ b/examples/minimal/go.sum @@ -2,6 +2,8 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= github.com/AlekSi/pointer v1.2.0 h1:glcy/gc4h8HnG2Z3ZECSzZ1IX1x2JxRVuDzaJwQE0+w= github.com/AlekSi/pointer v1.2.0/go.mod h1:gZGfd3dpW4vEc/UlyfKKi1roIqcCgwOIvb0tSNSBle0= +github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak= +github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= @@ -211,6 +213,8 @@ golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/exp v0.0.0-20240213143201-ec583247a57a h1:HinSgX1tJRX3KsL//Gxynpw5CTOAIPhgL4W8PNiIpVE= golang.org/x/exp v0.0.0-20240213143201-ec583247a57a/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc= +golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a h1:Jw5wfR+h9mnIYH+OtGT2im5wV1YGGDora5vTv/aa5bE= +golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8= @@ -281,3 +285,5 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.4.7 h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs= +honnef.co/go/tools v0.4.7/go.mod h1:+rnGS1THNh8zMwnd2oVOTL9QF6vmfyG6ZXBULae2uc0= diff --git a/examples/minimal/main.go b/examples/minimal/main.go index 8628494..67e8e45 100644 --- a/examples/minimal/main.go +++ b/examples/minimal/main.go @@ -1,10 +1,10 @@ package main import ( - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/cmdutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/cmdutil" "github.com/sirupsen/logrus" - "github.com/rebuy-de/rebuy-go-sdk/v7/examples/minimal/cmd" + "github.com/rebuy-de/rebuy-go-sdk/v8/examples/minimal/cmd" ) func main() { diff --git a/examples/minimal/tools.go b/examples/minimal/tools.go index fe3dedf..693342e 100644 --- a/examples/minimal/tools.go +++ b/examples/minimal/tools.go @@ -5,5 +5,6 @@ package main // https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module import ( - _ "github.com/rebuy-de/rebuy-go-sdk/v7/cmd/buildutil" + _ "github.com/rebuy-de/rebuy-go-sdk/v8/cmd/buildutil" + _ "honnef.co/go/tools/cmd/staticcheck" ) diff --git a/go.mod b/go.mod index 09f688c..c87277d 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/rebuy-de/rebuy-go-sdk/v7 +module github.com/rebuy-de/rebuy-go-sdk/v8 go 1.22.0 @@ -38,12 +38,14 @@ require ( golang.org/x/tools v0.18.0 google.golang.org/protobuf v1.32.0 gopkg.in/yaml.v3 v3.0.1 + honnef.co/go/tools v0.4.7 k8s.io/client-go v0.29.2 ) require ( dario.cat/mergo v1.0.0 // indirect github.com/AlekSi/pointer v1.2.0 // indirect + github.com/BurntSushi/toml v1.2.1 // indirect github.com/Masterminds/goutils v1.1.1 // indirect github.com/Masterminds/semver/v3 v3.2.1 // indirect github.com/Masterminds/sprig/v3 v3.2.3 // indirect @@ -137,6 +139,7 @@ require ( github.com/yuin/gopher-lua v1.1.0 // indirect gitlab.com/digitalxero/go-conventional-commit v1.0.7 // indirect golang.org/x/crypto v0.19.0 // indirect + golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a // indirect golang.org/x/net v0.21.0 // indirect golang.org/x/sys v0.17.0 // indirect golang.org/x/term v0.17.0 // indirect diff --git a/go.sum b/go.sum index 1771a1d..8b1aafb 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= github.com/AlekSi/pointer v1.2.0 h1:glcy/gc4h8HnG2Z3ZECSzZ1IX1x2JxRVuDzaJwQE0+w= github.com/AlekSi/pointer v1.2.0/go.mod h1:gZGfd3dpW4vEc/UlyfKKi1roIqcCgwOIvb0tSNSBle0= +github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak= +github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/DmitriyVTitov/size v1.5.0/go.mod h1:le6rNI4CoLQV1b9gzp1+3d7hMAD/uu2QcJ+aYbNgiU0= github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= @@ -380,6 +382,8 @@ golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/exp v0.0.0-20240213143201-ec583247a57a h1:HinSgX1tJRX3KsL//Gxynpw5CTOAIPhgL4W8PNiIpVE= golang.org/x/exp v0.0.0-20240213143201-ec583247a57a/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc= +golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a h1:Jw5wfR+h9mnIYH+OtGT2im5wV1YGGDora5vTv/aa5bE= +golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= @@ -485,6 +489,8 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.4.7 h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs= +honnef.co/go/tools v0.4.7/go.mod h1:+rnGS1THNh8zMwnd2oVOTL9QF6vmfyG6ZXBULae2uc0= k8s.io/api v0.29.2 h1:hBC7B9+MU+ptchxEqTNW2DkUosJpp1P+Wn6YncZ474A= k8s.io/api v0.29.2/go.mod h1:sdIaaKuU7P44aoyyLlikSLayT6Vb7bvJNCX105xZXY0= k8s.io/apimachinery v0.29.2 h1:EWGpfJ856oj11C52NRCHuU7rFDwxev48z+6DSlGNsV8= diff --git a/pkg/cmdutil/exit.go b/pkg/cmdutil/exit.go index 123104a..66af1a3 100644 --- a/pkg/cmdutil/exit.go +++ b/pkg/cmdutil/exit.go @@ -35,7 +35,7 @@ func Exit(code int) { // function. func HandleExit() { if e := recover(); e != nil { - if exit, ok := e.(exitCode); ok == true { + if exit, ok := e.(exitCode); ok { os.Exit(exit.code) } panic(e) // not an Exit, bubble up diff --git a/pkg/instutil/instutil.go b/pkg/instutil/instutil.go index 83bf017..706dfba 100644 --- a/pkg/instutil/instutil.go +++ b/pkg/instutil/instutil.go @@ -7,8 +7,8 @@ import ( "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/cmdutil" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/logutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/cmdutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/logutil" ) type contextKeyCounter string diff --git a/pkg/instutil/toolstack.go b/pkg/instutil/toolstack.go index 562b218..58cc36c 100644 --- a/pkg/instutil/toolstack.go +++ b/pkg/instutil/toolstack.go @@ -2,7 +2,7 @@ package instutil import ( "github.com/prometheus/client_golang/prometheus" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/cmdutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/cmdutil" ) func init() { diff --git a/pkg/instutil/transition.go b/pkg/instutil/transition.go index 2170a1c..00cf290 100644 --- a/pkg/instutil/transition.go +++ b/pkg/instutil/transition.go @@ -3,7 +3,7 @@ package instutil import ( "context" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/logutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/logutil" "github.com/sirupsen/logrus" ) diff --git a/pkg/lokiutil/buf.go b/pkg/lokiutil/buf.go index 17d2118..e555a2e 100644 --- a/pkg/lokiutil/buf.go +++ b/pkg/lokiutil/buf.go @@ -7,7 +7,7 @@ import ( "strings" "github.com/afiskon/promtail-client/logproto" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/cmdutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/cmdutil" "google.golang.org/protobuf/types/known/timestamppb" ) diff --git a/pkg/podutil/conn.go b/pkg/podutil/conn.go index 923945f..87a50f0 100644 --- a/pkg/podutil/conn.go +++ b/pkg/podutil/conn.go @@ -190,6 +190,9 @@ func (c *Connection) InspectContainer(name string) (*InspectContainerResult, err resp, err := c.request( RequestPath("containers/%s/json", name), ) + if err != nil { + return nil, err + } defer resp.Body.Close() if resp.StatusCode == http.StatusNotFound { diff --git a/pkg/podutil/dev.go b/pkg/podutil/dev.go index 33d800f..d817697 100644 --- a/pkg/podutil/dev.go +++ b/pkg/podutil/dev.go @@ -4,8 +4,8 @@ import ( "context" "fmt" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/cmdutil" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/logutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/cmdutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/logutil" ) func StartDevcontainer(ctx context.Context, conn *Connection, name string, image string, opts ...CreateContainerOption) (*InspectContainerResult, error) { diff --git a/pkg/redisutil/broadcast.go b/pkg/redisutil/broadcast.go index 18b2b2e..efbf911 100644 --- a/pkg/redisutil/broadcast.go +++ b/pkg/redisutil/broadcast.go @@ -68,6 +68,8 @@ func (b *Broadcast[T]) Read(ctx context.Context, id string) (*T, string, error) return nil, id, errors.WithStack(err) } + //lint:ignore SA4004 We just want to have the first message and + //returning withing two loops is easier than checking lengths. return value, sm.ID, nil } } diff --git a/pkg/testutil/golden_test.go b/pkg/testutil/golden_test.go index 1a7e0d8..54ca8fb 100644 --- a/pkg/testutil/golden_test.go +++ b/pkg/testutil/golden_test.go @@ -3,7 +3,7 @@ package testutil_test import ( "testing" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/testutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/testutil" ) type exampleData struct { diff --git a/pkg/typeutil/context.go b/pkg/typeutil/context.go index d56d768..de6bdea 100644 --- a/pkg/typeutil/context.go +++ b/pkg/typeutil/context.go @@ -5,7 +5,7 @@ import ( "fmt" ) -func FromContext[T any](ctx context.Context, key string) *T { +func FromContext[T any](ctx context.Context, key any) *T { raw := ctx.Value(key) if raw == nil { return nil @@ -19,15 +19,18 @@ func FromContext[T any](ctx context.Context, key string) *T { return typed } -func FromContextSingleton[T any](ctx context.Context) *T { - var name *T - return FromContext[T](ctx, fmt.Sprintf("singleton::%T", name)) +type singletonKey string + +func getSingletonKey[T any]() singletonKey { + var dummy *T + var name = fmt.Sprintf("%T", dummy) + return singletonKey(name) } -func ContextWithValue[T any](ctx context.Context, key string, value *T) context.Context { - return context.WithValue(ctx, key, value) +func FromContextSingleton[T any](ctx context.Context) *T { + return FromContext[T](ctx, getSingletonKey[T]()) } func ContextWithValueSingleton[T any](ctx context.Context, value *T) context.Context { - return ContextWithValue(ctx, fmt.Sprintf("singleton::%T", value), value) + return context.WithValue(ctx, getSingletonKey[T](), value) } diff --git a/pkg/vaultutil/aws.go b/pkg/vaultutil/aws.go index 5af2d64..e923764 100644 --- a/pkg/vaultutil/aws.go +++ b/pkg/vaultutil/aws.go @@ -7,7 +7,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/pkg/errors" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/logutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/logutil" ) type awsCredentialsProvider struct { diff --git a/pkg/vaultutil/manager.go b/pkg/vaultutil/manager.go index c6589d0..22c8022 100644 --- a/pkg/vaultutil/manager.go +++ b/pkg/vaultutil/manager.go @@ -7,7 +7,7 @@ import ( "github.com/aws/aws-sdk-go-v2/config" "github.com/hashicorp/vault/api" "github.com/pkg/errors" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/logutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/logutil" ) const ( diff --git a/pkg/vaultutil/params.go b/pkg/vaultutil/params.go index c1ec9af..40fe9ce 100644 --- a/pkg/vaultutil/params.go +++ b/pkg/vaultutil/params.go @@ -1,7 +1,7 @@ package vaultutil import ( - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/cmdutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/cmdutil" "github.com/spf13/cobra" ) diff --git a/pkg/vaultutil/util.go b/pkg/vaultutil/util.go index dfb862a..cda4b83 100644 --- a/pkg/vaultutil/util.go +++ b/pkg/vaultutil/util.go @@ -2,7 +2,7 @@ package vaultutil import ( "github.com/hashicorp/vault/api" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/logutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/logutil" ) func prettyPrintSecret(original *api.Secret) string { diff --git a/pkg/webutil/admin.go b/pkg/webutil/admin.go index cece84c..726604b 100644 --- a/pkg/webutil/admin.go +++ b/pkg/webutil/admin.go @@ -7,7 +7,7 @@ import ( "net/http/pprof" "github.com/prometheus/client_golang/prometheus/promhttp" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/logutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/logutil" ) func AdminAPIListenAndServe(ctx context.Context, healthy ...func() error) { diff --git a/pkg/webutil/auth.go b/pkg/webutil/auth.go index 0f8285c..dd9e62e 100644 --- a/pkg/webutil/auth.go +++ b/pkg/webutil/auth.go @@ -19,9 +19,9 @@ import ( "github.com/coreos/go-oidc/v3/oidc" "github.com/go-chi/chi/v5" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/cmdutil" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/logutil" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/typeutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/cmdutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/logutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/typeutil" "github.com/spf13/cobra" "golang.org/x/oauth2" ) diff --git a/pkg/webutil/server.go b/pkg/webutil/server.go index 41ac72b..64265f0 100644 --- a/pkg/webutil/server.go +++ b/pkg/webutil/server.go @@ -7,7 +7,7 @@ import ( "time" "github.com/pkg/errors" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/logutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/logutil" "golang.org/x/sync/errgroup" ) diff --git a/pkg/webutil/session.go b/pkg/webutil/session.go index 7e24986..a78a6a9 100644 --- a/pkg/webutil/session.go +++ b/pkg/webutil/session.go @@ -10,7 +10,7 @@ import ( "github.com/gorilla/securecookie" "github.com/gorilla/sessions" "github.com/pkg/errors" - "github.com/rebuy-de/rebuy-go-sdk/v7/pkg/cmdutil" + "github.com/rebuy-de/rebuy-go-sdk/v8/pkg/cmdutil" "github.com/redis/go-redis/v9" "github.com/sirupsen/logrus" ) diff --git a/tools.go b/tools.go new file mode 100644 index 0000000..19374ad --- /dev/null +++ b/tools.go @@ -0,0 +1,9 @@ +//go:build tools +// +build tools + +package main + +// https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module +import ( + _ "honnef.co/go/tools/cmd/staticcheck" +)