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