Files
bl/logic/main.go
昔念 db3a21dd91 feat(login): 引入基于 IP 的限流中间件
新增 github.com/xiaoqidun/limit 依赖,替换原有的全局速率限制器,
实现针对客户端 IP 的细粒度限流控制。在服务启动时初始化限流器,
并在程序退出前确保后台任务正确停止。同时更新 go.work 和 login/go.sum
文件以包含新的依赖项。此外,在 logic/main.go 中添加了主玩家数据
保存逻辑以确保服务关闭时数据持久化。
2025-10-24 23:14:36 +08:00

63 lines
1.2 KiB
Go

package main
import (
"fmt"
"os"
"runtime"
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
"github.com/gogf/gf/v2/os/gproc"
_ "blazing/contrib/drivers/pgsql"
"blazing/logic/service/fight"
"blazing/logic/service/player"
"blazing/cool"
//"blazing/o/service"
"net/http"
_ "net/http/pprof"
"github.com/gogf/gf/v2/os/gctx"
)
func PprofWeb() {
runtime.SetMutexProfileFraction(1) // (非必需)开启对锁调用的跟踪
runtime.SetBlockProfileRate(1) // (非必需)开启对阻塞操作的跟踪
err := http.ListenAndServe(":9909", nil)
if err != nil {
panic(err)
}
}
func signalHandlerForMain(sig os.Signal) {
fight.Fightpool.Release()
player.Mainplayer.Range(func(key uint32, value *player.Player) bool {
value.Save()
return true
})
fmt.Println("MainProcess is shutting down due to signal:", sig.String())
}
func main() {
if cool.IsRedisMode {
go cool.ListenFunc(gctx.New())
}
go Start(cool.Config.PortBL) //注入service
if cool.Config.PortBL == 1 { //只分析1服务器的
go PprofWeb()
}
fmt.Println("Process start, pid:", os.Getpid())
gproc.AddSigHandlerShutdown(
signalHandlerForMain,
)
gproc.Listen()
}