Skip to content

Commit

Permalink
make staticcheck pass
Browse files Browse the repository at this point in the history
  • Loading branch information
svenwltr committed Mar 13, 2024
1 parent f37b43f commit 94c6d6b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
12 changes: 9 additions & 3 deletions cmd/buildutil/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,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 @@ -324,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 @@ -354,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
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)
}

0 comments on commit 94c6d6b

Please sign in to comment.