From 63be630c68270e4dbdfb21291aad684f0b9ec8fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=BE=B7=E6=BB=A1?= Date: Sun, 18 Apr 2021 00:02:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E4=B8=8A=E4=B8=8B=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- context/context.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) 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, } }