diff --git a/server/handler/router.go b/server/handler/router.go index 5a1a15a6e9123b6b109246ec434fd71bc821e2ba..59f9400e16a0d2a81201d458dfc381f4829c7b57 100755 --- a/server/handler/router.go +++ b/server/handler/router.go @@ -10,6 +10,7 @@ package handler import ( "context" "net/http" + "strings" "time" "github.com/gin-contrib/timeout" @@ -28,25 +29,38 @@ func InitWebServer() { return } - go func() { - engine := gin.Default() - gin.SetMode(gin.ReleaseMode) - pluginclient.Global_Client.RegisterHandlers(engine) - InitRouter(engine) - StaticRouter(engine) + engine := gin.New() + engine.Use(gin.Recovery(), gin.Logger()) + gin.SetMode(gin.ReleaseMode) + pluginclient.Global_Client.RegisterHandlers(engine) + InitRouter(engine) + StaticRouter(engine) + + web := &http.Server{ + Addr: conf.Global_Config.Elk.Addr, + Handler: engine, + } + go func() { if conf.Global_Config.Elk.Https_enabled { - err := engine.RunTLS(conf.Global_Config.Elk.Addr, conf.Global_Config.Elk.Public_certificate, conf.Global_Config.Elk.Private_key) - if err != nil { + if err := web.ListenAndServeTLS(conf.Global_Config.Elk.Public_certificate, conf.Global_Config.Elk.Private_key); err != nil { + if strings.Contains(err.Error(), "Server closed") { + err = errors.Errorf("%s: %s, %s **errstack**2", err.Error(), conf.Global_Config.Elk.Public_certificate, conf.Global_Config.Elk.Private_key) + errormanager.ErrorTransmit(pluginclient.Global_Context, err, false) + return + } err = errors.Errorf("%s: %s, %s **errstackfatal**2", err.Error(), conf.Global_Config.Elk.Public_certificate, conf.Global_Config.Elk.Private_key) errormanager.ErrorTransmit(pluginclient.Global_Context, err, true) } - } else { - err := engine.Run(conf.Global_Config.Elk.Addr) - if err != nil { - err = errors.Errorf("%s **errstackfatal**2", err.Error()) - errormanager.ErrorTransmit(pluginclient.Global_Context, err, true) + } + if err := web.ListenAndServe(); err != nil { + if strings.Contains(err.Error(), "Server closed") { + err = errors.Errorf("%s **errstack**2", err.Error()) + errormanager.ErrorTransmit(pluginclient.Global_Context, err, false) + return } + err = errors.Errorf("%s **errstackfatal**2", err.Error()) + errormanager.ErrorTransmit(pluginclient.Global_Context, err, true) } }() }