优化代码

This commit is contained in:
flswld
2023-02-18 22:09:59 +08:00
parent 21fb9d400f
commit e580baeb46
37 changed files with 198 additions and 118 deletions

View File

@@ -5,7 +5,6 @@ import (
"os"
"os/signal"
"syscall"
"time"
"hk4e/common/config"
"hk4e/common/rpc"
@@ -18,6 +17,9 @@ func Run(ctx context.Context, configFile string) error {
logger.InitLogger("gm")
logger.Warn("gm start")
defer func() {
logger.CloseLogger()
}()
// natsrpc client
client, err := rpc.NewClient()
@@ -38,7 +40,6 @@ func Run(ctx context.Context, configFile string) error {
switch s {
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
logger.Warn("gm exit")
time.Sleep(time.Second)
return nil
case syscall.SIGHUP:
default:

View File

@@ -39,7 +39,7 @@ func (c *Controller) authorize() gin.HandlerFunc {
}
func (c *Controller) registerRouter() {
if config.CONF.Logger.Level == "DEBUG" {
if config.GetConfig().Logger.Level == "DEBUG" {
gin.SetMode(gin.DebugMode)
} else {
gin.SetMode(gin.ReleaseMode)
@@ -47,7 +47,7 @@ func (c *Controller) registerRouter() {
engine := gin.Default()
engine.Use(c.authorize())
engine.POST("/gm/cmd", c.gmCmd)
port := config.CONF.HttpPort
port := config.GetConfig().HttpPort
addr := ":" + strconv.Itoa(int(port))
err := engine.Run(addr)
if err != nil {

View File

@@ -18,6 +18,7 @@ func (c *Controller) gmCmd(context *gin.Context) {
gmCmdReq := new(GmCmdReq)
err := context.ShouldBindJSON(gmCmdReq)
if err != nil {
logger.Error("parse json error: %v", err)
return
}
rep, err := c.gm.Cmd(context.Request.Context(), &api.CmdRequest{