/
store.go
53 lines (47 loc) · 1.18 KB
/
store.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
package storage
import "net/http"
type Client interface {
Put(r *http.Request, fileField, toFilePath string, fileName ...string) (string, error)
PutFromFile(filePath, toFilePath string, fileName ...string) (string, error)
Delete(path string) error
}
var cli Client
func newInstance(c *config) Client {
switch c.Store {
case "cos":
cli = newCosInstance(c)
case "oss":
cli = newOssInstance(c)
case "qn":
cli = newQiniuInstance(c)
case "local":
cli = newLocalInstance(c)
}
return cli
}
func Parse(store string, maxFileSize int64, conf interface{}) Client {
c := &config{
Store: store,
maxFileSize: maxFileSize,
}
switch store {
case "local":
c.Local = conf.(LocalConfig)
case "oss":
c.OSS = conf.(OSSConfig)
case "cos":
c.COS = conf.(COSConfig)
case "qn":
c.QN = conf.(QNConfig)
}
return newInstance(c)
}
func Put(r *http.Request, fileField, toFilePath string, fileName ...string) (string, error) {
return cli.Put(r, fileField, toFilePath, fileName...)
}
func PutFromFile(filePath, toFilePath string, fileName ...string) (string, error) {
return cli.PutFromFile(filePath, toFilePath, fileName...)
}
func Delete(path string) error {
return cli.Delete(path)
}