mirror of
https://github.com/distribution/distribution.git
synced 2026-07-16 16:59:52 +00:00
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:
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
},
|
||||
},
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//go:build noresumabledigest
|
||||
// +build noresumabledigest
|
||||
|
||||
package storage
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user