Total Lines | 51 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package s3 |
||
2 | |||
3 | import ( |
||
4 | "context" |
||
5 | "time" |
||
6 | ) |
||
7 | |||
8 | // ExistObject checks if the object exists or not. |
||
9 | func (svc *S3) ExistObject(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.Exists, 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 | }) |
||
54 |