//Start will start EdgeHub
func (ehc *Controller) Start(ctx *context.Context) {
config.InitEdgehubConfig()
for {
err := ehc.initial(ctx)
...
err = ehc.chClient.Init()
...
// execute hook func after connect
ehc.pubConnectInfo(true)
go ehc.routeToEdge()
go ehc.routeToCloud()
go ehc.keepalive()
// wait the stop singal
// stop authinfo manager/websocket connection
<-ehc.stopChan
ehc.chClient.Uninit()
// execute hook fun after disconnect
ehc.pubConnectInfo(false)
// sleep one period of heartbeat, then try to connect cloud hub again
time.Sleep(ehc.config.HeartbeatPeriod * 2)
// clean channel
clean:
for {
select {
case <-ehc.stopChan:
default:
break clean
}
}
}
}