增加服务退出时, finish hook支持
This commit is contained in:
11
construct.go
11
construct.go
@ -60,7 +60,7 @@ var (
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 6:49 下午 2021/3/27
|
||||
func NewWebsocketServe(wsInstanceList ...abstract.IWebsocket) error {
|
||||
func NewWebsocketServe(finishHook func(), wsInstanceList ...abstract.IWebsocket) error {
|
||||
if len(wsInstanceList) == 0 {
|
||||
return errors.WithStack(errors.New("register websocket server list is empty"))
|
||||
}
|
||||
@ -70,7 +70,7 @@ func NewWebsocketServe(wsInstanceList ...abstract.IWebsocket) error {
|
||||
for _, wsInstance := range wsInstanceList {
|
||||
initServer(wsInstance)
|
||||
}
|
||||
run()
|
||||
run(finishHook)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -321,7 +321,7 @@ func dispatchCommand(ctx *context.WSContext, data []byte) error {
|
||||
}
|
||||
|
||||
// 启动所有端口的监听
|
||||
func run() {
|
||||
func run(finishHook func()) {
|
||||
for port, ginInstance := range ginRouterTable {
|
||||
go func(ginInstance *gin.Engine, port int) {
|
||||
if err := ginInstance.Run(fmt.Sprintf(":%d", port)); nil != err {
|
||||
@ -331,7 +331,10 @@ func run() {
|
||||
}
|
||||
|
||||
<-sigChan
|
||||
// TODO : 增加后置hook
|
||||
// 增加后置hook
|
||||
if nil != finishHook {
|
||||
finishHook()
|
||||
}
|
||||
}
|
||||
|
||||
// Stop 停止服务
|
||||
|
||||
Reference in New Issue
Block a user