mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-26 18:04:22 +00:00
friendly apis for constructors
This commit is contained in:
+14
-2
@@ -78,7 +78,7 @@ type Switch struct {
|
||||
}
|
||||
|
||||
// NewSwitch creates a new Switch with the given config.
|
||||
func NewSwitch(cfg *config.P2PConfig, metrics *Metrics) *Switch {
|
||||
func NewSwitch(cfg *config.P2PConfig, options ...func(*Switch)) *Switch {
|
||||
sw := &Switch{
|
||||
config: cfg,
|
||||
reactors: make(map[string]Reactor),
|
||||
@@ -87,7 +87,7 @@ func NewSwitch(cfg *config.P2PConfig, metrics *Metrics) *Switch {
|
||||
peers: NewPeerSet(),
|
||||
dialing: cmn.NewCMap(),
|
||||
reconnecting: cmn.NewCMap(),
|
||||
metrics: metrics,
|
||||
metrics: NopMetrics(),
|
||||
}
|
||||
|
||||
// Ensure we have a completely undeterministic PRNG.
|
||||
@@ -102,9 +102,21 @@ func NewSwitch(cfg *config.P2PConfig, metrics *Metrics) *Switch {
|
||||
sw.mConfig = mConfig
|
||||
|
||||
sw.BaseService = *cmn.NewBaseService(nil, "P2P Switch", sw)
|
||||
|
||||
for _, option := range options {
|
||||
option(sw)
|
||||
}
|
||||
|
||||
return sw
|
||||
}
|
||||
|
||||
// WithMetrics sets the metrics.
|
||||
func WithMetrics(metrics *Metrics) func(*Switch) {
|
||||
return func(sw *Switch) {
|
||||
sw.metrics = metrics
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Switch setup
|
||||
|
||||
|
||||
Reference in New Issue
Block a user