/
s3_handler.go
57 lines (46 loc) · 1.14 KB
/
s3_handler.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
51
52
53
54
55
56
57
package util
import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/golang/glog"
)
type S3ObjectStorageHandler struct {
S3Client *s3.Client
S3Endpoint string
}
func InitS3ObjectStorageHandler() (*S3ObjectStorageHandler, error) {
endpoint := "https://s3.computational.bio.uni-giessen.de"
cfg, err := config.LoadDefaultConfig(
context.Background(),
config.WithRegion("RegionOne"),
config.WithEndpointResolver(aws.EndpointResolverFunc(
func(service, region string) (aws.Endpoint, error) {
return aws.Endpoint{
URL: endpoint,
}, nil
})),
)
if err != nil {
glog.Errorln(err.Error())
return nil, err
}
client := s3.NewFromConfig(cfg)
handler := S3ObjectStorageHandler{
S3Client: client,
S3Endpoint: endpoint,
}
return &handler, nil
}
func (handler *S3ObjectStorageHandler) DeleteObject(bucket string, key string) error {
_, err := handler.S3Client.DeleteObject(context.Background(), &s3.DeleteObjectInput{
Bucket: &bucket,
Key: &key,
})
if err != nil {
glog.Errorln(err.Error())
return err
}
return nil
}