Skip to content

Commit

Permalink
refactor: 调整上下文key
Browse files Browse the repository at this point in the history
  • Loading branch information
ppanphper committed Nov 5, 2024
1 parent ea84528 commit 9e307a0
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion znet/ws_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import (
"github.com/gorilla/websocket"
)

// WsConnectionHttpReqCtxKey http请求上下文key
type WsConnectionHttpReqCtxKey struct{}

// WsConnection is a module for handling the read and write operations of a WebSocket connection.
// (Websocket连接模块, 用于处理 Websocket 连接的读写业务 一个连接对应一个Connection)
type WsConnection struct {
Expand Down Expand Up @@ -116,7 +119,7 @@ type WsConnection struct {
func newWebsocketConn(server ziface.IServer, conn *websocket.Conn, connID uint64, r *http.Request) ziface.IConnection {
// Initialize Conn properties (初始化Conn属性)
c := &WsConnection{
ctx: context.WithValue(context.Background(), "http.request.context", r.Context()), // websocketAuth可以在上下文中传递特殊的参数或信息;比如鉴权后,设置一些用户信息或房间id
ctx: context.WithValue(context.Background(), WsConnectionHttpReqCtxKey{}, r.Context()), // websocketAuth可以在上下文中传递特殊的参数或信息;比如鉴权后,设置一些用户信息或房间id
conn: conn,
connID: connID,
connIdStr: strconv.FormatUint(connID, 10),
Expand Down

0 comments on commit 9e307a0

Please sign in to comment.