by RObin
This commit is contained in:
parent
b8a9b7e66b
commit
4983f71f0e
|
@ -116,7 +116,8 @@ func main() {
|
||||||
Addr: fmt.Sprintf("%s:%d", GetIp(), cfg.App.Port),
|
Addr: fmt.Sprintf("%s:%d", GetIp(), cfg.App.Port),
|
||||||
Handler: router,
|
Handler: router,
|
||||||
}
|
}
|
||||||
httpserver.StartHttpServer(srv, cfg.DefaultConfig)
|
//httpserver.StartHttpServer(srv, cfg.DefaultConfig)
|
||||||
|
httpserver.StartOfflineHttpServer(srv, cfg.DefaultConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrintAndExit(msg string) {
|
func PrintAndExit(msg string) {
|
||||||
|
|
|
@ -142,17 +142,4 @@ elastic_search:
|
||||||
uri: "http://172.31.37.67:9200"
|
uri: "http://172.31.37.67:9200"
|
||||||
username: "elastic"
|
username: "elastic"
|
||||||
password: "Wishpal@2024"
|
password: "Wishpal@2024"
|
||||||
sniff: false
|
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
|
|
|
@ -143,16 +143,4 @@ elastic_search:
|
||||||
uri: "http://127.0.0.1:9200"
|
uri: "http://127.0.0.1:9200"
|
||||||
username: "elastic"
|
username: "elastic"
|
||||||
password: "Wishpal@2024"
|
password: "Wishpal@2024"
|
||||||
sniff: false
|
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
|
|
|
@ -40,3 +40,31 @@ func StartHttpServer(srv *http.Server, cfg *configcenter.DefaultConfig) {
|
||||||
|
|
||||||
logger.Info("Server exited")
|
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")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue