/
storage.go
41 lines (34 loc) · 919 Bytes
/
storage.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
// SPDX-FileCopyrightText: Copyright (c) 2023-2024, CIQ, Inc. All rights reserved
// SPDX-License-Identifier: Apache-2.0
package storage
import (
"context"
"fmt"
"gocloud.dev/blob"
)
func GetPrefix(config Config) string {
prefix := config.Prefix
if prefix != "" && prefix != "/" {
if prefix[0] == '/' {
prefix = prefix[1:]
} else if prefix[len(prefix)-1] != '/' {
prefix += "/"
}
} else if prefix == "/" {
prefix = ""
}
return prefix
}
func Init(ctx context.Context, config Config, prefix string) (*blob.Bucket, error) {
switch config.Driver {
case S3StorageDriver:
return initS3(ctx, config.S3, prefix)
case FSStorageDriver:
return initFS(ctx, config.Filesystem, prefix)
case GCSStorageDriver:
return initGCS(ctx, config.GCS, prefix)
case AzureStorageDriver:
return initAzure(ctx, config.Azure, prefix)
}
return nil, fmt.Errorf("unknown storage driver %s", config.Driver)
}