diff --git a/context/context.go b/context/context.go index f27acff..9e472c9 100644 --- a/context/context.go +++ b/context/context.go @@ -12,6 +12,10 @@ import ( "strings" "time" + "github.com/go-developer/gopkg/easylock" + + "github.com/go-developer/gopkg/easymap" + "github.com/gin-gonic/gin" "github.com/go-developer/gopkg/util" "gopkg.in/olahol/melody.v1" @@ -23,11 +27,13 @@ import ( // // Date : 7:03 下午 2021/3/27 type WSContext struct { - ConnectionID string // 请求ID - Flag string // 长连接模块 - GinCtx *gin.Context // 基于gin实现websocket, gin的上下文 - Session *melody.Session // 长连接的会话 - Server *melody.Melody // ws server + ConnectionID string // 请求ID + Flag string // 长连接模块 + GinCtx *gin.Context // 基于gin实现websocket, gin的上下文 + Session *melody.Session // 长连接的会话 + Server *melody.Melody // ws server + Data easymap.EasyMap // 上下文中存储的数据 + Lock easylock.EasyLock // 数据锁 } // NewContext 生成上下文信息 @@ -36,12 +42,16 @@ type WSContext struct { // // Date : 7:15 下午 2021/3/27 func NewContext(ginCtx *gin.Context, flag string, session *melody.Session) *WSContext { + d, _ := easymap.NewSegment(128, true) + l, _ := easylock.NewSegment(128) return &WSContext{ ConnectionID: generateConnectionID(), Flag: flag, GinCtx: ginCtx, Session: session, Server: melody.New(), + Data: d, + Lock: l, } }