forked from goodrain/rainbond
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudos.go
68 lines (57 loc) · 1.34 KB
/
cloudos.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package cloudos
import (
"errors"
)
var (
// ErrUnsupportedS3Provider -
ErrUnsupportedS3Provider = errors.New("unsupported s3 provider")
)
// S3Provider -
type S3Provider string
var (
// S3ProviderS3 -
S3ProviderS3 S3Provider = "s3"
// S3ProviderAliOSS -
S3ProviderAliOSS S3Provider = "alioss"
)
func (p S3Provider) String() string {
return string(p)
}
// Str2S3Provider converts a string to S3Provider.
func Str2S3Provider(value string) (S3Provider, error) {
switch value {
case S3ProviderS3.String():
return S3ProviderS3, nil
case S3ProviderAliOSS.String():
return S3ProviderAliOSS, nil
default:
return "", ErrUnsupportedS3Provider
}
}
// CloudOSer is the interface that wraps the required methods to interact with cloud object storage.
type CloudOSer interface {
PutObject(objkey, filepath string) error
GetObject(objectKey, filePath string) error
DeleteObject(objkey string) error
}
// New returns a new CloudOSer.
func New(cfg *Config) (CloudOSer, error) {
switch cfg.ProviderType {
case S3ProviderAliOSS:
return newAliOSS(cfg)
case S3ProviderS3:
return newS3(cfg)
default:
return nil, ErrUnsupportedS3Provider
}
}
// Config configuration about cloud object storage.
type Config struct {
ProviderType S3Provider
Endpoint string
AccessKey string
SecretKey string
UseSSL bool
BucketName string
Location string
}