mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-04 14:22:26 +08:00
优化代码
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"hk4e/common/config"
|
||||
"hk4e/common/rpc"
|
||||
@@ -20,6 +19,9 @@ func Run(ctx context.Context, configFile string) error {
|
||||
|
||||
logger.InitLogger("dispatch")
|
||||
logger.Warn("dispatch start")
|
||||
defer func() {
|
||||
logger.CloseLogger()
|
||||
}()
|
||||
|
||||
db := dao.NewDao()
|
||||
defer db.CloseDao()
|
||||
@@ -43,8 +45,6 @@ func Run(ctx context.Context, configFile string) error {
|
||||
switch s {
|
||||
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
|
||||
logger.Warn("dispatch exit")
|
||||
|
||||
time.Sleep(time.Second)
|
||||
return nil
|
||||
case syscall.SIGHUP:
|
||||
default:
|
||||
|
||||
@@ -60,7 +60,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)
|
||||
@@ -138,7 +138,7 @@ func (c *Controller) registerRouter() {
|
||||
engine.Use(c.authorize())
|
||||
engine.POST("/gate/token/verify", c.gateTokenVerify)
|
||||
engine.POST("/gate/token/reset", c.gateTokenReset)
|
||||
port := config.CONF.HttpPort
|
||||
port := config.GetConfig().HttpPort
|
||||
addr := ":" + strconv.Itoa(int(port))
|
||||
err := engine.Run(addr)
|
||||
if err != nil {
|
||||
|
||||
@@ -20,7 +20,7 @@ type Dao struct {
|
||||
|
||||
func NewDao() (r *Dao) {
|
||||
r = new(Dao)
|
||||
clientOptions := options.Client().ApplyURI(config.CONF.Database.Url).SetMinPoolSize(10).SetMaxPoolSize(100)
|
||||
clientOptions := options.Client().ApplyURI(config.GetConfig().Database.Url).SetMinPoolSize(10).SetMaxPoolSize(100)
|
||||
client, err := mongo.Connect(context.TODO(), clientOptions)
|
||||
if err != nil {
|
||||
logger.Error("mongo connect error: %v", err)
|
||||
@@ -34,8 +34,8 @@ func NewDao() (r *Dao) {
|
||||
r.mongo = client
|
||||
r.db = client.Database("dispatch_hk4e")
|
||||
r.redis = redis.NewClient(&redis.Options{
|
||||
Addr: config.CONF.Redis.Addr,
|
||||
Password: config.CONF.Redis.Password,
|
||||
Addr: config.GetConfig().Redis.Addr,
|
||||
Password: config.GetConfig().Redis.Password,
|
||||
DB: 0,
|
||||
PoolSize: 10,
|
||||
MinIdleConns: 1,
|
||||
|
||||
Reference in New Issue
Block a user