Passed
Push — master ( c97320...c60853 )
by eval
02:30 queued 01:07
created

s3.*S3.GetPresignURL   A

Complexity

Conditions 1

Size

Total Lines 7
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nop 4
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
package s3
2
3
import (
4
	"context"
5
	"time"
6
)
7
8
// IsExistObject checks if the object exists or not.
9
func (svc *S3) IsExistObject(ctx context.Context, bucket, path string) (bool, error) {
10
	res, err := svc.HeadObject(ctx, HeadObjectRequest{
11
		Bucket: bucket,
12
		Key:    path,
13
	})
14
	if err != nil {
15
		return false, err
16
	}
17
	return res.IsExist, nil
18
}
19
20
// GetObjectFromPath gets an object from `path`.
21
func (svc *S3) GetObjectFromPath(ctx context.Context, bucket, path string) (*GetObjectResult, error) {
22
	return svc.GetObject(ctx, GetObjectRequest{
23
		Bucket: bucket,
24
		Key:    path,
25
	})
26
}
27
28
// GetPresignURL gets an presigned url of the object for GET.
29
func (svc *S3) GetPresignURL(ctx context.Context, bucket, path string, dur time.Duration) (string, error) {
30
	in := GetObjectRequest{
31
		Bucket: bucket,
32
		Key:    path,
33
	}.ToInput()
34
	r := svc.client.GetObjectRequest(in)
35
	return r.Presign(dur)
36
}
37
38
// DeleteObjectFromPath deletes an object from `path`.
39
func (svc *S3) DeleteObjectFromPath(ctx context.Context, bucket, path string) (*DeleteObjectResult, error) {
40
	return svc.DeleteObject(ctx, DeleteObjectRequest{
41
		Bucket: bucket,
42
		Key:    path,
43
	})
44
}
45
46
// PutObjectToPath puts an object to the `path` and bytes data.
47
func (svc *S3) PutObjectToPath(ctx context.Context, bucket, path string, data []byte) (*PutObjectResult, error) {
48
	return svc.PutObject(ctx, PutObjectRequest{
49
		Bucket:    bucket,
50
		Key:       path,
51
		BodyBytes: data,
52
	})
53
}
54