func NewZookeeperServiceManager(servers string, timeout time.Duration) skynet.ServiceManager { sm := &ZookeeperServiceManager{ done: make(chan bool), watchers: make([]watcher, 0, 0), managedInstances: make(map[string]skynet.ServiceInfo), } c, session, err := factory(strings.Split(servers, ","), timeout) if err != nil { log.Panic(err) } sm.conn = c sm.session = session err = sm.createDefaultPaths() if err != nil && err != zk.ErrNodeExists { log.Panic(err) } sm.cache, err = NewInstanceCache(sm) if err != nil { log.Panic(err) } go sm.mux() return sm }
func main() { testService := NewTestService() serviceInfo := skynet.NewServiceInfo("TestService", "1.0.0") service := service.CreateService(testService, serviceInfo) // handle panic so that we remove ourselves from the pool in case // of catastrophic failure defer func() { service.Shutdown() if err := recover(); err != nil { log.Panic("Unrecovered error occured: ", err) } }() waiter := service.Start() // waiting on the sync.WaitGroup returned by service.Start() will // wait for the service to finish running. waiter.Wait() }