本文整理匯總了Golang中github.com/centrifugal/centrifugo/libcentrifugo.Application.Shutdown方法的典型用法代碼示例。如果您正苦於以下問題:Golang Application.Shutdown方法的具體用法?Golang Application.Shutdown怎麽用?Golang Application.Shutdown使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/centrifugal/centrifugo/libcentrifugo.Application
的用法示例。
在下文中一共展示了Application.Shutdown方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: handleSignals
func handleSignals(app *libcentrifugo.Application) {
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, syscall.SIGHUP, syscall.SIGINT, os.Interrupt)
for {
sig := <-sigc
logger.INFO.Println("Signal received:", sig)
switch sig {
case syscall.SIGHUP:
// reload application configuration on SIGHUP
logger.INFO.Println("Reloading configuration")
err := viper.ReadInConfig()
if err != nil {
switch err.(type) {
case viper.ConfigParseError:
logger.CRITICAL.Printf("Error parsing configuration: %s\n", err)
continue
default:
logger.CRITICAL.Println("No config file found")
continue
}
}
setupLogging()
c := newConfig()
app.SetConfig(c)
logger.INFO.Println("Configuration successfully reloaded")
case syscall.SIGINT, os.Interrupt:
logger.INFO.Println("Shutting down")
go time.AfterFunc(10*time.Second, func() {
os.Exit(1)
})
app.Shutdown()
os.Exit(130)
}
}
}
示例2: handleSignals
func handleSignals(app *libcentrifugo.Application) {
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, syscall.SIGHUP, syscall.SIGINT, os.Interrupt)
for {
sig := <-sigc
logger.INFO.Println("signal received:", sig)
switch sig {
case syscall.SIGHUP:
// reload application configuration on SIGHUP
// note that you should run checkconfig before reloading configuration
// as Viper exits when encounters parsing errors
logger.INFO.Println("reloading configuration")
err := viper.ReadInConfig()
if err != nil {
logger.CRITICAL.Println("unable to locate config file")
return
}
setupLogging()
c := newConfig()
s := structureFromConfig(nil)
app.SetConfig(c)
app.SetStructure(s)
case syscall.SIGINT, os.Interrupt:
logger.INFO.Println("shutting down")
go time.AfterFunc(5*time.Second, func() {
os.Exit(1)
})
app.Shutdown()
os.Exit(130)
}
}
}