This commit is contained in:
Leufolium 2024-05-24 04:30:34 +08:00
parent b8a9b7e66b
commit 4983f71f0e
4 changed files with 32 additions and 28 deletions

View File

@ -116,7 +116,8 @@ func main() {
Addr: fmt.Sprintf("%s:%d", GetIp(), cfg.App.Port),
Handler: router,
}
httpserver.StartHttpServer(srv, cfg.DefaultConfig)
//httpserver.StartHttpServer(srv, cfg.DefaultConfig)
httpserver.StartOfflineHttpServer(srv, cfg.DefaultConfig)
}
func PrintAndExit(msg string) {

View File

@ -143,16 +143,3 @@ elastic_search:
username: "elastic"
password: "Wishpal@2024"
sniff: false
offline_server:
log:
stdout_enable: true
stdout_level: "trace"
file_enable: true
file_level: "trace"
file_abs_path: "/app/ironfan/log/offline-server/"
app:
app_name: "offline-server"
ip: "127.0.0.1"
port: 9998

View File

@ -144,15 +144,3 @@ elastic_search:
username: "elastic"
password: "Wishpal@2024"
sniff: false
offline_server_log:
stdout_enable: true
stdout_level: "trace"
file_enable: true
file_level: "trace"
file_abs_path: "/app/ironfan/log/offline-server/"
offline_server_app:
app_name: "offline-server"
ip: "127.0.0.1"
port: 9998

View File

@ -40,3 +40,31 @@ func StartHttpServer(srv *http.Server, cfg *configcenter.DefaultConfig) {
logger.Info("Server exited")
}
func StartOfflineHttpServer(srv *http.Server, cfg *configcenter.DefaultConfig) {
go func() {
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
logger.Fatal("listen: %v", err)
}
}()
logger.Info("Server %s start at %s", cfg.App.AppName, srv.Addr)
quit := make(chan os.Signal)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
logger.Info("Shutdown Server ...")
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
if err := srv.Shutdown(ctx); err != nil {
log.Fatal("Server Shutdown:", err)
}
select {
case <-ctx.Done():
logger.Info("timeout of 1 seconds.")
}
logger.Info("Server exited")
}