diff --git a/consul/discovery.go b/consul/discovery.go index 8c75d4c..3105879 100644 --- a/consul/discovery.go +++ b/consul/discovery.go @@ -92,16 +92,23 @@ func (s *Service) Register() error { return err } - go func(s *Service) { // startup register + return nil +} +func (s *Service) Unregister() error { + return s.agent.ServiceDeregister(s.GetID()) +} + +func (s *Service) InitTTL() { + go func() { // startup register ticker := time.NewTicker(time.Second * 1) for range ticker.C { if ok, _ := s.healthCheck(); ok { ticker.Stop() } } - }(s) + }() - go func(s *Service) { // TTL + go func() { // TTL interval := s.ttl - time.Second*2 // 2 seconds overhead ticker := time.NewTicker(interval) for range ticker.C { @@ -109,12 +116,7 @@ func (s *Service) Register() error { fmt.Printf("TTL Error #: %v\n", err) } } - }(s) - - return nil -} -func (s *Service) Unregister() error { - return s.agent.ServiceDeregister(s.GetID()) + }() } func (s *Service) Connect() (*connect.Service, error) {