- 将命令行参数解析移至 controller 包的 init 函数中 - 添加 PortBL 配置项判断,实现 login 服务器的条件初始化 - 移除 main 函数中的重复代码 - 在 login 服务器中启用 pprof 性能分析工具 - 删除未使用的 Start 函数和相关代码
69 lines
1.4 KiB
Go
69 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
|
|
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
|
|
"github.com/gogf/gf/v2/os/gproc"
|
|
|
|
_ "blazing/contrib/drivers/pgsql"
|
|
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
|
|
"blazing/common/socket"
|
|
"blazing/common/socket/handler"
|
|
"blazing/cool"
|
|
"blazing/logic/controller"
|
|
|
|
//"blazing/o/service"
|
|
|
|
"blazing/modules/blazing/service"
|
|
|
|
"github.com/gogf/gf/v2/os/gctx"
|
|
)
|
|
|
|
func signalHandlerForMain(sig os.Signal) {
|
|
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
|
|
fmt.Println("Process start, pid:", os.Getpid())
|
|
gproc.AddSigHandlerShutdown(
|
|
|
|
signalHandlerForMain,
|
|
)
|
|
|
|
gproc.Listen()
|
|
}
|
|
|
|
// 如果id是0,那就是login server
|
|
func Start(serverid uint32) {
|
|
|
|
head := handler.NewTomeeHandler()
|
|
head.Callback = controller.Recv
|
|
if serverid != 0 {
|
|
// 确定端口
|
|
port, err := determinePort(serverid)
|
|
if err != nil {
|
|
log.Fatalf("Failed to determine port: %v", err)
|
|
}
|
|
|
|
//随机端口产生,然后给sql注册端口
|
|
service.NewLoginServiceService().SetServerID(serverid, gconv.Uint16(port))
|
|
socket.NewServer(socket.WithCORS(), socket.WithPort(port), socket.WithSocketHandler(head)).Start()
|
|
|
|
} else {
|
|
|
|
socket.NewServer(socket.WithCORS(), socket.WithPort(defaultPort), socket.WithSocketHandler(head)).Start()
|
|
}
|
|
|
|
}
|