1
|
|
|
package s3 |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
SDK "github.com/aws/aws-sdk-go-v2/service/s3" |
5
|
|
|
|
6
|
|
|
"github.com/evalphobia/aws-sdk-go-v2-wrapper/config" |
7
|
|
|
"github.com/evalphobia/aws-sdk-go-v2-wrapper/errors" |
8
|
|
|
"github.com/evalphobia/aws-sdk-go-v2-wrapper/log" |
9
|
|
|
) |
10
|
|
|
|
11
|
|
|
const ( |
12
|
|
|
serviceName = "S3" |
13
|
|
|
) |
14
|
|
|
|
15
|
|
|
// S3 has S3 client. |
16
|
|
|
type S3 struct { |
17
|
|
|
client *SDK.Client |
18
|
|
|
|
19
|
|
|
logger log.Logger |
20
|
|
|
errWrap func(errors.ErrorData) error |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
// New returns initialized *S3. |
24
|
|
|
func New(conf config.Config) (*S3, error) { |
25
|
|
|
c, err := conf.AWSConfig() |
26
|
|
|
if err != nil { |
27
|
|
|
return nil, err |
28
|
|
|
} |
29
|
|
|
if conf.Endpoints.HasS3() { |
30
|
|
|
c.EndpointResolver = conf.Endpoints.GetS3() |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
cli := SDK.New(c) |
34
|
|
|
// use force path style when using custom endpoint |
35
|
|
|
switch { |
36
|
|
|
case conf.Endpoints.HasS3(), |
37
|
|
|
conf.CommonEndpoint != "": |
38
|
|
|
cli.ForcePathStyle = true |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
svc := &S3{ |
42
|
|
|
client: cli, |
43
|
|
|
logger: conf.GetLogger(), |
44
|
|
|
errWrap: conf.GetErrWrap(), |
45
|
|
|
} |
46
|
|
|
return svc, nil |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
// GetClient gets original SDK client. |
50
|
|
|
func (svc *S3) GetClient() *SDK.Client { |
51
|
|
|
return svc.client |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
// SetLogger sets logger. |
55
|
|
|
func (svc *S3) SetLogger(logger log.Logger) { |
56
|
|
|
svc.logger = logger |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
// Infof logging information. |
60
|
|
|
func (svc *S3) Infof(format string, v ...interface{}) { |
61
|
|
|
svc.logger.Infof(serviceName, format, v...) |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
// Errorf logging error information. |
65
|
|
|
func (svc *S3) Errorf(format string, v ...interface{}) { |
66
|
|
|
svc.logger.Errorf(serviceName, format, v...) |
|
|
|
|
67
|
|
|
} |
68
|
|
|
|