forked from skip-mev/connect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
83 lines (67 loc) · 1.89 KB
/
options.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
package oracle
import (
"time"
"go.uber.org/zap"
"github.com/skip-mev/slinky/oracle/config"
oraclemetrics "github.com/skip-mev/slinky/oracle/metrics"
"github.com/skip-mev/slinky/oracle/types"
)
// Option is a function that can be used to configure an Oracle.
type Option func(*OracleImpl)
// WithUpdateInterval sets the update interval on the Oracle.
func WithUpdateInterval(updateInterval time.Duration) Option {
return func(o *OracleImpl) {
if updateInterval <= 0 {
panic("update interval must be positive")
}
o.updateInterval = updateInterval
}
}
// WithMaxCacheAge sets the max cache age on the Oracle.
func WithMaxCacheAge(maxCacheAge time.Duration) Option {
return func(o *OracleImpl) {
if maxCacheAge <= 0 {
panic("max cache age must be positive")
}
o.maxCacheAge = maxCacheAge
}
}
// WithLogger sets the logger on the Oracle.
func WithLogger(logger *zap.Logger) Option {
return func(o *OracleImpl) {
if logger == nil {
panic("cannot set nil logger")
}
o.logger = logger.With(zap.String("process", "oracle"))
}
}
// WithMetrics sets the metrics on the Oracle.
func WithMetrics(metrics oraclemetrics.Metrics) Option {
return func(o *OracleImpl) {
if metrics == nil {
panic("cannot set nil metrics")
}
o.metrics = metrics
}
}
// WithMetricsConfig sets the metrics on the oracle from the given config.
func WithMetricsConfig(config config.MetricsConfig) Option {
return func(o *OracleImpl) {
o.metrics = oraclemetrics.NewMetricsFromConfig(config)
}
}
// WithPriceAggregator sets the data aggregator on the Oracle.
func WithPriceAggregator(agg PriceAggregator) Option {
return func(o *OracleImpl) {
if agg == nil {
panic("cannot set nil aggregator")
}
o.priceAggregator = agg
}
}
// WithProviders sets the providers on the Oracle.
func WithProviders(providers []*types.PriceProvider) Option {
return func(o *OracleImpl) {
o.providers = providers
}
}