Skip to content

Commit 8e3ac27

Browse files
committed
Use goroutine
1 parent b82618b commit 8e3ac27

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ go 1.15
55
require (
66
github.com/aws/aws-sdk-go v1.37.1
77
github.com/prometheus/client_golang v1.9.0
8+
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
89
)

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ
312312
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
313313
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
314314
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
315+
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
315316
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
316317
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
317318
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=

main.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"strconv"
99
"strings"
10+
"sync"
1011
"time"
1112

1213
"github.com/aws/aws-sdk-go/aws"
@@ -109,16 +110,25 @@ func getECRImageScanFindings(repositories []string) error {
109110
return fmt.Errorf("failed to get image tags: %w", err)
110111
}
111112

113+
var wg sync.WaitGroup
114+
112115
for _, repo := range repositories {
113116
for _, imageTag := range imageTags {
114-
result, err := describeImageScanFindings(svc, repo, imageTag)
115-
if err != nil {
116-
return fmt.Errorf("failed to describe image scan findings: %w", err)
117-
}
117+
wg.Add(1)
118118

119-
collectMetrics(result)
119+
go func(svc *ecr.ECR, repo string, imageTag string) {
120+
result, err := describeImageScanFindings(svc, repo, imageTag)
121+
if err != nil {
122+
log.Printf("failed to describe image scan findings: %v", err)
123+
}
124+
125+
collectMetrics(result)
126+
wg.Done()
127+
}(svc, repo, imageTag)
120128
}
121129
}
130+
wg.Wait()
131+
122132
return nil
123133
}
124134

0 commit comments

Comments
 (0)