refactor: add All method so that we can range over services dynamically
This commit is contained in:
parent
6bf557346d
commit
7578665ba4
|
@ -11,4 +11,5 @@ type Service interface {
|
|||
type Services interface {
|
||||
P2P() P2PService
|
||||
Registry() RegistryService
|
||||
All() []Service
|
||||
}
|
||||
|
|
26
node/node.go
26
node/node.go
|
@ -94,25 +94,17 @@ func (n *NodeImpl) Start() error {
|
|||
|
||||
n.started = true
|
||||
|
||||
err = n.Services().P2P().Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, svc := range n.services.All() {
|
||||
err := svc.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = n.Services().P2P().Start()
|
||||
if err != nil {
|
||||
return err
|
||||
err = svc.Start()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
err = n.Services().Registry().Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = n.Services().Registry().Start()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
n.started = true
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -11,6 +11,14 @@ type ServicesImpl struct {
|
|||
registry interfaces.RegistryService
|
||||
}
|
||||
|
||||
func (s *ServicesImpl) All() []interfaces.Service {
|
||||
services := make([]interfaces.Service, 0)
|
||||
services = append(services, s.p2p)
|
||||
services = append(services, s.registry)
|
||||
|
||||
return services
|
||||
}
|
||||
|
||||
func (s *ServicesImpl) Registry() interfaces.RegistryService {
|
||||
return s.registry
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue