-
Notifications
You must be signed in to change notification settings - Fork 40
/
customize_config.go
141 lines (129 loc) · 3.55 KB
/
customize_config.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package gfspconfig
import (
"errors"
"github.com/bnb-chain/greenfield-storage-provider/core/consensus"
"github.com/bnb-chain/greenfield-storage-provider/core/piecestore"
corercmgr "github.com/bnb-chain/greenfield-storage-provider/core/rcmgr"
"github.com/bnb-chain/greenfield-storage-provider/core/spdb"
coretaskqueue "github.com/bnb-chain/greenfield-storage-provider/core/taskqueue"
)
func CustomizeGfSpDB(db spdb.SPDB) Option {
return func(cfg *GfSpConfig) error {
if cfg.Customize == nil {
cfg.Customize = &Customize{}
}
if cfg.Customize.GfSpDB != nil {
return errors.New("repeated set sp db")
}
cfg.Customize.GfSpDB = db
return nil
}
}
func CustomizePieceStore(store piecestore.PieceStore) Option {
return func(cfg *GfSpConfig) error {
if cfg.Customize == nil {
cfg.Customize = &Customize{}
}
if cfg.Customize.PieceStore != nil {
return errors.New("repeated set piece store")
}
cfg.Customize.PieceStore = store
return nil
}
}
func CustomizePieceOp(op piecestore.PieceOp) Option {
return func(cfg *GfSpConfig) error {
if cfg.Customize == nil {
cfg.Customize = &Customize{}
}
if cfg.Customize.PieceOp != nil {
return errors.New("repeated set piece op")
}
cfg.Customize.PieceOp = op
return nil
}
}
func CustomizeRcmgr(rcmgr corercmgr.ResourceManager) Option {
return func(cfg *GfSpConfig) error {
if cfg.Customize == nil {
cfg.Customize = &Customize{}
}
if cfg.Customize.Rcmgr != nil {
return errors.New("repeated set rcmgr")
}
cfg.Customize.Rcmgr = rcmgr
return nil
}
}
func CustomizeRcLimiter(limiter corercmgr.Limiter) Option {
return func(cfg *GfSpConfig) error {
if cfg.Customize == nil {
cfg.Customize = &Customize{}
}
if cfg.Customize.RcLimiter != nil {
return errors.New("repeated set rc limiter")
}
cfg.Customize.RcLimiter = limiter
return nil
}
}
func CustomizeConsensus(consensus consensus.Consensus) Option {
return func(cfg *GfSpConfig) error {
if cfg.Customize == nil {
cfg.Customize = &Customize{}
}
if cfg.Customize.Consensus != nil {
return errors.New("repeated set consensus")
}
cfg.Customize.Consensus = consensus
return nil
}
}
func CustomizeTQueue(newFunc coretaskqueue.NewTQueue) Option {
return func(cfg *GfSpConfig) error {
if cfg.Customize == nil {
cfg.Customize = &Customize{}
}
if cfg.Customize.NewTQueueFunc != nil {
return errors.New("repeated set task queue")
}
cfg.Customize.NewTQueueFunc = newFunc
return nil
}
}
func CustomizeTQueueWithLimit(newFunc coretaskqueue.NewTQueueWithLimit) Option {
return func(cfg *GfSpConfig) error {
if cfg.Customize == nil {
cfg.Customize = &Customize{}
}
if cfg.Customize.NewTQueueWithLimit != nil {
return errors.New("repeated set strategy task queue with limit")
}
cfg.Customize.NewTQueueWithLimit = newFunc
return nil
}
}
func CustomizeStrategyTQueue(newFunc coretaskqueue.NewTQueueOnStrategy) Option {
return func(cfg *GfSpConfig) error {
if cfg.Customize == nil {
cfg.Customize = &Customize{}
}
if cfg.Customize.NewStrategyTQueueFunc != nil {
return errors.New("repeated set strategy task queue")
}
cfg.Customize.NewStrategyTQueueFunc = newFunc
return nil
}
}
func CustomizeStrategyTQueueWithLimit(newFunc coretaskqueue.NewTQueueOnStrategyWithLimit) Option {
return func(cfg *GfSpConfig) error {
if cfg.Customize == nil {
cfg.Customize = &Customize{}
}
if cfg.Customize.NewStrategyTQueueWithLimitFunc != nil {
return errors.New("repeated set strategy task queue with limit")
}
cfg.Customize.NewStrategyTQueueWithLimitFunc = newFunc
return nil
}
}