From 5d1b42b237e400926bc9d716ff67a3148ff06984 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 25 May 2024 11:38:28 +0800 Subject: [PATCH] 1 --- server/statserver/common/types.go | 4 ++++ server/statserver/constant/constant.go | 1 + server/statserver/controller/stat.go | 4 ++-- server/statserver/global/global.go | 9 +++++++++ server/statserver/session/export.go | 11 ++++++++++- server/statserver/session/sessionmgr.go | 6 ++++++ 6 files changed, 32 insertions(+), 3 deletions(-) diff --git a/server/statserver/common/types.go b/server/statserver/common/types.go index d91b69ae..0f92f93b 100644 --- a/server/statserver/common/types.go +++ b/server/statserver/common/types.go @@ -6,3 +6,7 @@ import ( type App interface { Run(func(), func()) } + +type SessionMgr interface { + UpdateSession(accountId string, sessionId string) +} diff --git a/server/statserver/constant/constant.go b/server/statserver/constant/constant.go index d8dd29ec..29399ca9 100644 --- a/server/statserver/constant/constant.go +++ b/server/statserver/constant/constant.go @@ -3,5 +3,6 @@ package constant const ( APP_MODULE_IDX = iota CONTROLLER_MGR_MODULE_IDX + SESSION_MGR_MODULE_IDX MAX_MODULE_IDX ) diff --git a/server/statserver/controller/stat.go b/server/statserver/controller/stat.go index 582dfc2a..48a9e25d 100644 --- a/server/statserver/controller/stat.go +++ b/server/statserver/controller/stat.go @@ -1,7 +1,7 @@ package controller import ( - "main/session" + . "main/global" "github.com/gin-gonic/gin" ) @@ -12,7 +12,7 @@ type Stat struct { func (this *Stat) caUpdateSession(c *gin.Context) { accountId := c.DefaultQuery("account_id", "") sessionId := c.DefaultQuery("session_id", "") - session.SessionMgr.UpdateSession(accountId, sessionId); + GetSessionMgr().UpdateSession(accountId, sessionId); rspObj := struct { ErrCode int32 `json:"errcode"` ErrMsg string `json:"errmsg"` diff --git a/server/statserver/global/global.go b/server/statserver/global/global.go index 6868ff2f..d3c625c4 100644 --- a/server/statserver/global/global.go +++ b/server/statserver/global/global.go @@ -9,14 +9,19 @@ import ( var modules [constant.MAX_MODULE_IDX]q5.Module var initOrders = []int32{ + constant.SESSION_MGR_MODULE_IDX, } var app common.App +var sessionMgr common.SessionMgr func GetApp() common.App { return app } +func GetSessionMgr() common.SessionMgr { + return sessionMgr +} func RegModule(idx int32, m q5.Module) { fmt.Printf("RegModule module %d\n", idx) @@ -26,6 +31,10 @@ func RegModule(idx int32, m q5.Module) { { app = m.(common.App) } + case constant.SESSION_MGR_MODULE_IDX: + { + sessionMgr = m.(common.SessionMgr) + } default: { panic("unknow module") diff --git a/server/statserver/session/export.go b/server/statserver/session/export.go index 14e89a1c..61b9d757 100644 --- a/server/statserver/session/export.go +++ b/server/statserver/session/export.go @@ -1,3 +1,12 @@ package session -var SessionMgr = new (sessionMgr) +import ( + "main/constant" + "main/global" +) + +var _sessionMgr = new (sessionMgr) + +func init() { + global.RegModule(constant.SESSION_MGR_MODULE_IDX, _sessionMgr) +} diff --git a/server/statserver/session/sessionmgr.go b/server/statserver/session/sessionmgr.go index 2d6dc199..71a8a364 100644 --- a/server/statserver/session/sessionmgr.go +++ b/server/statserver/session/sessionmgr.go @@ -16,6 +16,12 @@ type sessionMgr struct { lock sync.Mutex } +func (this *sessionMgr) Init() { +} + +func (this *sessionMgr) UnInit() { +} + func (this *sessionMgr) UpdateSession(accountId string, sessionId string) { session := this.getSession(accountId) if session != nil {