chore: smol go fix changes

This PR changes the code based on the `go fix` suggestions
to modernize the codebase and keep up with the latest Go features.

Signed-off-by: Milos Gajdos <milosthegajdos@gmail.com>
This commit is contained in:
Milos Gajdos
2026-05-24 15:56:02 -07:00
parent ade782b145
commit 0d5789588f
8 changed files with 13 additions and 22 deletions

View File

@@ -482,7 +482,7 @@ func (suite *ConfigSuite) TestParseEnvInlinedStruct() {
func checkStructs(tt *testing.T, t reflect.Type, structsChecked map[string]struct{}) {
tt.Helper()
for t.Kind() == reflect.Ptr || t.Kind() == reflect.Map || t.Kind() == reflect.Slice {
for t.Kind() == reflect.Pointer || t.Kind() == reflect.Map || t.Kind() == reflect.Slice {
t = t.Elem()
}

View File

@@ -155,7 +155,7 @@ func (p *Parser) Parse(in []byte, v any) error {
// through the environment. Precondition: an empty path slice must never be
// passed in.
func (p *Parser) overwriteFields(v reflect.Value, fullpath string, path []string, payload string) error {
for v.Kind() == reflect.Ptr {
for v.Kind() == reflect.Pointer {
if v.IsNil() {
return fmt.Errorf("encountered nil pointer while handling environment variable %s", fullpath)
}
@@ -191,8 +191,7 @@ func (p *Parser) overwriteFields(v reflect.Value, fullpath string, path []string
return p.overwriteFields(v.Elem(), fullpath, path, payload)
}
// Interface was empty; create an implicit map
var template map[string]any
wrappedV := reflect.MakeMap(reflect.TypeOf(template))
wrappedV := reflect.MakeMap(reflect.TypeFor[map[string]any]())
v.Set(wrappedV)
return p.overwriteMap(wrappedV, fullpath, path, payload)
}
@@ -252,7 +251,7 @@ func (p *Parser) overwriteStruct(v reflect.Value, fullpath string, path []string
if field.IsNil() {
field.Set(reflect.MakeMap(sf.Type))
}
case reflect.Ptr:
case reflect.Pointer:
if field.IsNil() {
field.Set(reflect.New(field.Type().Elem()))
}
@@ -281,7 +280,7 @@ func (p *Parser) overwriteMap(m reflect.Value, fullpath string, path []string, p
mapValue := m.MapIndex(k)
// If the existing value is nil, we want to
// recreate it instead of using this value.
if (mapValue.Kind() == reflect.Ptr ||
if (mapValue.Kind() == reflect.Pointer ||
mapValue.Kind() == reflect.Interface ||
mapValue.Kind() == reflect.Map) &&
mapValue.IsNil() {

View File

@@ -122,8 +122,8 @@ func TestParseInlinedStruct(t *testing.T) {
p := NewParser("registry", []VersionedParseInfo{
{
Version: "0.1",
ParseAs: reflect.TypeOf(config),
ConversionFunc: func(c interface{}) (interface{}, error) {
ParseAs: reflect.TypeFor[localConfiguration](),
ConversionFunc: func(c any) (any, error) {
return c, nil
},
},

View File

@@ -368,10 +368,7 @@ func (t *tags) List(ctx context.Context, limit int, last string) ([]string, erro
return nil, err
}
preAlloc := 1000
if limit < preAlloc {
preAlloc = limit
}
preAlloc := min(limit, 1000)
tags := make([]string, 0, preAlloc)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, listURL.String(), nil)
if err != nil {

View File

@@ -432,9 +432,7 @@ func testProxyStoreServe(t *testing.T, te *testEnv, numClients int) {
for range numClients {
// Serveblob - pulls through blobs
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
for _, remoteBlob := range te.inRemote {
w := httptest.NewRecorder()
r, err := http.NewRequest(http.MethodGet, "", nil)
@@ -475,7 +473,7 @@ func testProxyStoreServe(t *testing.T, te *testEnv, numClients int) {
delete(descHitMap, desc.Digest)
hitLock.Unlock()
}
}()
})
}
wg.Wait()

View File

@@ -1,5 +1,4 @@
//go:build noresumabledigest
// +build noresumabledigest
package storage

View File

@@ -109,7 +109,7 @@ func compareReplaceInline(s1, s2 string, old, new byte) int {
l := min(len(s2), len(s1))
for i := 0; i < l; i++ {
for i := range l {
c1, c2 := s1[i], s2[i]
if c1 == old {
c1 = new

View File

@@ -35,13 +35,11 @@ func TestRegulatorEnterExit(t *testing.T) {
var secondGroupDone sync.WaitGroup
for range 50 {
secondGroupReady.Add(1)
secondGroupDone.Add(1)
go func() {
secondGroupDone.Go(func() {
secondGroupReady.Done()
r.enter()
r.exit()
secondGroupDone.Done()
}()
})
}
secondGroupReady.Wait()