-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (42 loc) · 1.06 KB
/
main.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
50
package main
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"os"
)
func main() {
c, err := GetConfig("./conf/audiofp.conf")
if err != nil {
fmt.Println("Config file not found")
return
}
fileToRemove := os.Args[2]
// Initialize a client using Spaces
s3Config := &aws.Config{
Credentials: credentials.NewStaticCredentials(c.Bucket.AccessKey, c.Bucket.SecretKey, ""),
Endpoint: aws.String(c.Bucket.Endpoint),
Region: aws.String(c.Bucket.Region),
}
newSession := session.New(s3Config)
svc := s3.New(newSession)
input := &s3.DeleteObjectInput{
Bucket: aws.String(c.Bucket.Name),
Key: aws.String(fileToRemove),
}
_, err = svc.DeleteObject(input)
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
default:
fmt.Println(aerr.Error())
}
} else {
fmt.Println(err.Error())
}
}
fmt.Printf("Successfully remove %s\n", fileToRemove)
}