From 2e83d913ba2380c5e8fa2cd01da07c1721a5b29b Mon Sep 17 00:00:00 2001 From: guoguangwu Date: Thu, 21 Sep 2023 09:53:24 +0800 Subject: [PATCH] chore: slice loop replace Signed-off-by: guoguangwu --- oci/casext/refname_dir_test.go | 4 +--- oci/config/generate/spec.go | 28 +++++++--------------------- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/oci/casext/refname_dir_test.go b/oci/casext/refname_dir_test.go index c47ea40a4..d6323aea9 100644 --- a/oci/casext/refname_dir_test.go +++ b/oci/casext/refname_dir_test.go @@ -156,9 +156,7 @@ func fakeSetupEngine(t *testing.T, engineExt Engine) ([]descriptorMap, error) { MediaType: ispec.MediaTypeImageManifest, Config: configDescriptor, } - for _, layer := range layerDescriptors { - manifest.Layers = append(manifest.Layers, layer) - } + manifest.Layers = append(manifest.Layers, layerDescriptors...) manifestDigest, manifestSize, err := engineExt.PutBlobJSON(ctx, manifest) if err != nil { diff --git a/oci/config/generate/spec.go b/oci/config/generate/spec.go index 95a2d1e64..b42a9d00c 100644 --- a/oci/config/generate/spec.go +++ b/oci/config/generate/spec.go @@ -162,9 +162,7 @@ func (g *Generator) AddConfigEnv(name, value string) { // ConfigEnv returns the list of environment variables to be used in a container. func (g *Generator) ConfigEnv() []string { copy := []string{} - for _, v := range g.image.Config.Env { - copy = append(copy, v) - } + copy = append(copy, g.image.Config.Env...) return copy } @@ -176,9 +174,7 @@ func (g *Generator) ClearConfigEntrypoint() { // SetConfigEntrypoint sets the list of arguments to use as the command to execute when the container starts. func (g *Generator) SetConfigEntrypoint(entrypoint []string) { copy := []string{} - for _, v := range entrypoint { - copy = append(copy, v) - } + copy = append(copy, entrypoint...) g.image.Config.Entrypoint = copy } @@ -186,9 +182,7 @@ func (g *Generator) SetConfigEntrypoint(entrypoint []string) { func (g *Generator) ConfigEntrypoint() []string { // We have to make a copy to preserve the privacy of g.image.Config. copy := []string{} - for _, v := range g.image.Config.Entrypoint { - copy = append(copy, v) - } + copy = append(copy, g.image.Config.Entrypoint...) return copy } @@ -200,9 +194,7 @@ func (g *Generator) ClearConfigCmd() { // SetConfigCmd sets the list of default arguments to the entrypoint of the container. func (g *Generator) SetConfigCmd(cmd []string) { copy := []string{} - for _, v := range cmd { - copy = append(copy, v) - } + copy = append(copy, cmd...) g.image.Config.Cmd = copy } @@ -210,9 +202,7 @@ func (g *Generator) SetConfigCmd(cmd []string) { func (g *Generator) ConfigCmd() []string { // We have to make a copy to preserve the privacy of g.image.Config. copy := []string{} - for _, v := range g.image.Config.Cmd { - copy = append(copy, v) - } + copy = append(copy, g.image.Config.Cmd...) return copy } @@ -309,9 +299,7 @@ func (g *Generator) AddRootfsDiffID(diffid digest.Digest) { // RootfsDiffIDs returns the the array of layer content hashes (DiffIDs), in order from bottom-most to top-most. func (g *Generator) RootfsDiffIDs() []digest.Digest { copy := []digest.Digest{} - for _, v := range g.image.RootFS.DiffIDs { - copy = append(copy, v) - } + copy = append(copy, g.image.RootFS.DiffIDs...) return copy } @@ -328,9 +316,7 @@ func (g *Generator) AddHistory(history ispec.History) { // History returns the history of each layer. func (g *Generator) History() []ispec.History { copy := []ispec.History{} - for _, v := range g.image.History { - copy = append(copy, v) - } + copy = append(copy, g.image.History...) return copy }