Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PF-3455 add staticcheck #194

Merged
merged 4 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion buildutil
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env sh
set -eu
go mod vendor
test -z "$(go env GOWORK)" && go mod vendor || go work vendor
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am testing go work for simplifying major upgrades. Unfortunately go mod vendor complains and demands to use go work vendor. I tried to make it a oneliner to keep the file small and because we would to add this everywhere.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know about go work until you mentioned it here.

I tried to make it a oneliner to keep the file small and because we would to add this everywhere.

Do we really? We'd only need this in projects that use go work and not everywhere, don't we?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, see my test setup below. If I try to call go mod vendor on anywhere in the projects directory, Go throws an error at me.

image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And to actually explain why I try to use go work: When I do a breaking change, I can immediately see the impact on those other projects without need for modifying to go.mod in each project.

So I would do a breaking change and then call my hack/buildall.sh hack, which is basically a for loop.

go generate ./...
exec go run ./cmd/buildutil "$@"
14 changes: 11 additions & 3 deletions cmd/buildutil/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ type BuildInfo struct {
Module string
Dir string
Version string
Work string
}

Commit struct {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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" {
Expand Down Expand Up @@ -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{}
Expand Down
23 changes: 22 additions & 1 deletion cmd/buildutil/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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...)
Expand Down
1 change: 0 additions & 1 deletion examples/full/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions examples/full/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ require (
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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions examples/full/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
1 change: 1 addition & 0 deletions examples/full/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ 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"
_ "honnef.co/go/tools/cmd/staticcheck"
svenwltr marked this conversation as resolved.
Show resolved Hide resolved
)
3 changes: 3 additions & 0 deletions examples/minimal/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ require (
github.com/rebuy-de/rebuy-go-sdk/v7 v7.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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions examples/minimal/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
1 change: 1 addition & 0 deletions examples/minimal/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ 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"
_ "honnef.co/go/tools/cmd/staticcheck"
)
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmdutil/exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pkg/podutil/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions pkg/redisutil/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
17 changes: 10 additions & 7 deletions pkg/typeutil/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
9 changes: 9 additions & 0 deletions tools.go
Original file line number Diff line number Diff line change
@@ -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"
)
Loading