-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.go
42 lines (37 loc) · 1.06 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
package stores
import (
"fmt"
"strings"
"time"
"github.com/nzai/qr/exchanges"
"github.com/nzai/qr/quotes"
"go.uber.org/zap"
)
// Store define exchange daily quote store
type Store interface {
// Exists exchange daily quote exists
Exists(exchanges.Exchange, time.Time) (bool, error)
// Save save exchange daily quote
Save(exchanges.Exchange, time.Time, *quotes.ExchangeDailyQuote) error
// Load load exchange daily quote
Load(exchanges.Exchange, time.Time) (*quotes.ExchangeDailyQuote, error)
// Close close exchange daily quote store
Close() error
}
// Parse parse command argument
func Parse(arg string) (Store, error) {
parts := strings.Split(arg, ":")
if len(parts) != 2 {
zap.L().Error("store arg invalid", zap.String("arg", arg))
return nil, fmt.Errorf("store arg invalid: %s", arg)
}
switch parts[0] {
case "fs":
return NewFileSystem(parts[1]), nil
case "leveldb":
return NewLevelDB(parts[1]), nil
default:
zap.L().Error("store type invalid", zap.String("type", parts[0]))
return nil, fmt.Errorf("store type invalid: %s", parts[0])
}
}