-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstorage.go
53 lines (45 loc) · 1.33 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
package kimg
import (
"errors"
"log"
)
// KimgStorage is a interface to provide storage in kimg.
type KimgStorage interface {
Set(req *KimgRequest, data []byte) error
Get(req *KimgRequest) ([]byte, error)
Del(req *KimgRequest) error
}
// KimgBaseStorage base storage struct hold kimg context.
type KimgBaseStorage struct {
ctx *KimgContext
}
// Debug log
func (storage *KimgBaseStorage) Debug(format string, v ...interface{}) {
storage.ctx.Logger.Debug(format, v...)
}
// Info log
func (storage *KimgBaseStorage) Info(format string, v ...interface{}) {
storage.ctx.Logger.Info(format, v...)
}
// Warn log
func (storage *KimgBaseStorage) Warn(format string, v ...interface{}) {
storage.ctx.Logger.Warn(format, v...)
}
// Error log
func (storage *KimgBaseStorage) Error(format string, v ...interface{}) {
storage.ctx.Logger.Error(format, v...)
}
// NewKimgStorage create a storage instance according to storage mode in config.
func NewKimgStorage(ctx *KimgContext) (KimgStorage, error) {
switch ctx.Config.Storage.Mode {
case "file":
log.Println("[INFO] storage [file] used")
return NewKimgFileStorage(ctx)
case "minio":
log.Println("[INFO] storage [minio] used")
return NewKimgMinioStorage(ctx)
default:
log.Printf("[WARN] unsupported storage mode :%s\n", ctx.Config.Storage.Mode)
return nil, errors.New("not available storage")
}
}