mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-04 18:22:26 +08:00
refactor
This commit is contained in:
@@ -1,43 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
_ "net/http/pprof"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"hk4e/common/config"
|
||||
"hk4e/dispatch/controller"
|
||||
"hk4e/dispatch/dao"
|
||||
"hk4e/pkg/logger"
|
||||
"hk4e/dispatch/app"
|
||||
)
|
||||
|
||||
var (
|
||||
config = flag.String("config", "application.toml", "config file")
|
||||
)
|
||||
|
||||
func main() {
|
||||
filePath := "./application.toml"
|
||||
config.InitConfig(filePath)
|
||||
|
||||
logger.InitLogger("dispatch", config.CONF.Logger)
|
||||
logger.LOG.Info("dispatch start")
|
||||
|
||||
db := dao.NewDao()
|
||||
|
||||
_ = controller.NewController(db)
|
||||
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
|
||||
for {
|
||||
s := <-c
|
||||
logger.LOG.Info("get a signal %s", s.String())
|
||||
switch s {
|
||||
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
|
||||
logger.LOG.Info("dispatch exit")
|
||||
db.CloseDao()
|
||||
time.Sleep(time.Second)
|
||||
return
|
||||
case syscall.SIGHUP:
|
||||
default:
|
||||
return
|
||||
}
|
||||
flag.Parse()
|
||||
//go statsviz_serve.Serve("0.0.0.0:2345")
|
||||
err := app.Run(context.TODO(), *config)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user