This commit is contained in:
aozhiwei 2024-05-25 11:38:28 +08:00
parent 9329fae43e
commit 5d1b42b237
6 changed files with 32 additions and 3 deletions

View File

@ -6,3 +6,7 @@ import (
type App interface {
Run(func(), func())
}
type SessionMgr interface {
UpdateSession(accountId string, sessionId string)
}

View File

@ -3,5 +3,6 @@ package constant
const (
APP_MODULE_IDX = iota
CONTROLLER_MGR_MODULE_IDX
SESSION_MGR_MODULE_IDX
MAX_MODULE_IDX
)

View File

@ -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"`

View File

@ -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")

View File

@ -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)
}

View File

@ -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 {