-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.go
54 lines (43 loc) · 1.5 KB
/
client.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
package ezstorage
import (
"context"
"errors"
"time"
"github.com/achintya-7/ez-storage/internal/gcp"
"github.com/achintya-7/ez-storage/model"
"google.golang.org/api/option"
)
type StorageConfig struct {
Type string
Context context.Context
GcsOption []option.ClientOption
}
type StorageFunctioner interface {
ListBuckets(ctx context.Context, projectId string) (buckets []string, err error)
ListObjects(ctx context.Context, bucket, path string) (objs []string, err error)
GetPathSize(ctx context.Context, bucket string, path string) (size int64, err error)
DeleteFolder(ctx context.Context, bucket, path string) (err error)
GetSignedDownloadURL(ctx context.Context, bucket, path string, expiry time.Time) (url string, err error)
GetSignedUploadUrl(ctx context.Context, bucket, path string, expiry time.Time) (url string, err error)
GetAttributes(ctx context.Context, bucket, path string) (attrs *model.ObjAttrs, err error)
}
// todo: Implement AWS client
func NewClient(configs StorageConfig) (storageClient StorageFunctioner, err error) {
if configs.Context == nil {
configs.Context = context.Background()
}
switch configs.Type {
case model.GCP:
opts := []option.ClientOption{}
opts = append(opts, configs.GcsOption...)
gcpClient, err := gcp.NewGcpClient(configs.Context, opts)
if err != nil {
return nil, err
}
return gcpClient, nil
case model.AWS:
default:
return nil, errors.New("invalid storage type in config")
}
return nil, errors.New("invalid storage type in config")
}