-
Notifications
You must be signed in to change notification settings - Fork 9
/
bucket.go
46 lines (38 loc) · 1.03 KB
/
bucket.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
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package s3
import (
"context"
"io"
"time"
"github.com/aws/aws-sdk-go-v2/service/s3"
)
type Bucket struct {
BucketName string
S3Client *s3.Client
}
type PutObjectOpt func(*s3.PutObjectInput)
func WithExpiration(expiration time.Time) PutObjectOpt {
return func(input *s3.PutObjectInput) {
input.Expires = &expiration
}
}
func (b Bucket) GetObject(ctx context.Context, key string) (*s3.GetObjectOutput, error) {
output, err := b.S3Client.GetObject(ctx, &s3.GetObjectInput{
Bucket: &b.BucketName,
Key: &key,
})
return output, err
}
func (b Bucket) PutObject(ctx context.Context, key string, body io.Reader, opts ...PutObjectOpt) (*s3.PutObjectOutput, error) {
input := &s3.PutObjectInput{
Bucket: &b.BucketName,
Key: &key,
Body: body,
}
for _, opt := range opts {
opt(input)
}
return b.S3Client.PutObject(ctx, input)
}