connect to all stuff on start

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2020-10-28 10:51:09 +03:00
parent 14c97d59c1
commit 9553f46cf4

View File

@ -1,6 +1,7 @@
package micro package micro
import ( import (
"fmt"
rtime "runtime" rtime "runtime"
"sync" "sync"
@ -136,17 +137,47 @@ func (s *service) String() string {
} }
func (s *service) Start() error { func (s *service) Start() error {
var err error
if logger.V(logger.InfoLevel) { if logger.V(logger.InfoLevel) {
logger.Infof("Starting [service] %s", s.Name()) logger.Infof("Starting [service] %s", s.Name())
} }
var err error
for _, fn := range s.opts.BeforeStart { for _, fn := range s.opts.BeforeStart {
if err = fn(); err != nil { if err = fn(); err != nil {
return err return err
} }
} }
if s.opts.Server == nil {
return fmt.Errorf("cant start nil server")
}
if s.opts.Registry != nil {
if err := s.opts.Registry.Connect(s.opts.Context); err != nil {
return err
}
}
if s.opts.Broker != nil {
if err := s.opts.Broker.Connect(s.opts.Context); err != nil {
return err
}
}
/*
if s.opts.Transport != nil {
if err := s.opts.Transport.Connect(s.opts.Context); err != nil {
return err
}
}
*/
if s.opts.Store != nil {
if err := s.opts.Store.Connect(s.opts.Context); err != nil {
return err
}
}
if err = s.opts.Server.Start(); err != nil { if err = s.opts.Server.Start(); err != nil {
return err return err
} }