@@ -10,6 +10,7 @@ import (
1010 "io"
1111 "io/ioutil"
1212 "path/filepath"
13+ "slices"
1314 "strings"
1415 "time"
1516
@@ -147,10 +148,8 @@ func GetContainerRunningStatus(containerName string) (string, error) {
147148 }
148149 // Loop through containers to find the one with the given name
149150 for _ , container := range containers {
150- for _ , name := range container .Names {
151- if name == "/" + containerName {
152- return container .Status , nil
153- }
151+ if slices .Contains (container .Names , "/" + containerName ) {
152+ return container .Status , nil
154153 }
155154 }
156155 return status , fmt .Errorf ("Unable to get container running status: %v" , containerName )
@@ -535,12 +534,12 @@ func GetLatestContainerInfo(containerType string) (map[string]string, error) {
535534 return res , err
536535 }
537536 // Convert JSON to map
538- var m map [string ]interface {}
537+ var m map [string ]any
539538 err = json .Unmarshal (jsonData , & m )
540539 if err != nil {
541540 return res , err
542541 }
543- containerData , ok := m [containerType ].(map [string ]interface {} )
542+ containerData , ok := m [containerType ].(map [string ]any )
544543 if ! ok {
545544 return nil , fmt .Errorf ("%s data is not a map" , containerType )
546545 }
@@ -606,10 +605,8 @@ func PullImageIfNotExist(desiredImage string, imageInfo map[string]string) (bool
606605 return false , err
607606 }
608607 for _ , img := range images {
609- for _ , digest := range img .RepoDigests {
610- if digest == fmt .Sprintf ("%s@sha256:%s" , imageInfo ["repo" ], imageInfo ["hash" ]) {
611- return true , nil
612- }
608+ if slices .Contains (img .RepoDigests , fmt .Sprintf ("%s@sha256:%s" , imageInfo ["repo" ], imageInfo ["hash" ])) {
609+ return true , nil
613610 }
614611 }
615612 resp , err := cli .ImagePull (ctx , fmt .Sprintf ("%s@sha256:%s" , imageInfo ["repo" ], imageInfo ["hash" ]), imagetypes.PullOptions {})
@@ -635,15 +632,11 @@ func PullImageByRef(imageRef string) error {
635632 return err
636633 }
637634 for _ , img := range images {
638- for _ , tag := range img .RepoTags {
639- if tag == imageRef {
640- return nil
641- }
635+ if slices .Contains (img .RepoTags , imageRef ) {
636+ return nil
642637 }
643- for _ , digest := range img .RepoDigests {
644- if digest == imageRef {
645- return nil
646- }
638+ if slices .Contains (img .RepoDigests , imageRef ) {
639+ return nil
647640 }
648641 }
649642
@@ -751,10 +744,8 @@ func GetContainerIDByName(ctx context.Context, cli *client.Client, name string)
751744 return "" , err
752745 }
753746 for _ , container := range containers {
754- for _ , n := range container .Names {
755- if n == "/" + name {
756- return container .ID , nil
757- }
747+ if slices .Contains (container .Names , "/" + name ) {
748+ return container .ID , nil
758749 }
759750 }
760751 return "" , fmt .Errorf ("Container not found" )
@@ -783,12 +774,7 @@ func RestartContainer(name string) error {
783774}
784775
785776func contains (slice []string , str string ) bool {
786- for _ , item := range slice {
787- if item == str {
788- return true
789- }
790- }
791- return false
777+ return slices .Contains (slice , str )
792778}
793779
794780func volumeExists (volumeName string ) (bool , error ) {
0 commit comments