-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths3.go
49 lines (44 loc) · 1.37 KB
/
s3.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"log"
)
func DeleteS3Folder(key string, housekeepConfig HousekeepConfig) {
svc := s3.New(session.New())
if housekeepConfig.isVerbose() {
log.Printf("Getting %s from %s", key, housekeepConfig.bucket)
}
params := &s3.ListObjectsInput{
Bucket: aws.String(housekeepConfig.bucket),
Prefix: aws.String(key + "/"),
}
err := svc.ListObjectsPages(params, func(page *s3.ListObjectsOutput, lastPage bool) bool {
for _, obj := range page.Contents {
if housekeepConfig.dryRun {
if housekeepConfig.isInfo() {
log.Printf(" Would delete %s", *obj.Key)
}
} else {
if housekeepConfig.isVerbose() {
log.Printf(" Deleting %s", *obj.Key)
}
req := &s3.DeleteObjectInput{
Bucket: aws.String(housekeepConfig.bucket),
Key: obj.Key,
}
_, err := svc.DeleteObject(req)
if err != nil {
log.Fatalf("Error %s", err)
return false
}
}
}
return true
})
if err != nil {
log.Fatalf("Error %s", err)
return
}
}