升级上下文
This commit is contained in:
parent
854c9b0ad7
commit
63be630c68
@ -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"
|
||||
@ -28,6 +32,8 @@ type WSContext struct {
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user