This commit is contained in:
2025-06-27 21:03:23 +08:00
parent 0f29dccec4
commit 54dc7ba173
5 changed files with 188 additions and 11 deletions

View File

@@ -26,8 +26,8 @@ type ISocketServer interface {
// ISocketConn 由网络层实现
type ISocketConn interface {
GetParam(key string) interface{}
SetParam(key string, values interface{})
GetParam(key string) string
SetParam(key string, values string)
Write(data []byte) error
Close() error
}

View File

@@ -66,7 +66,7 @@ func (s *WSServer) OnOpen(c gnet.Conn) ([]byte, gnet.Action) {
curHeader: nil,
cachedBuf: bytes.Buffer{},
},
param: make(map[string]interface{}),
param: make(map[string]string),
}
c.SetContext(ws)
s.unUpgradeConn.Store(c.RemoteAddr().String(), ws)

View File

@@ -19,7 +19,7 @@ type WSConn struct {
logger logging.Logger
isUpgrade bool
isClose bool
param map[string]interface{}
param map[string]string
openTime int64
wsMessageBuf
}
@@ -163,15 +163,17 @@ func (w *WSConn) OnRequest(u []byte) error {
if err != nil {
return err
}
w.SetParam("query", parsedURL.Query())
for key, value := range parsedURL.Query() {
w.SetParam(key, value[0])
}
return nil
}
func (w *WSConn) GetParam(key string) interface{} {
func (w *WSConn) GetParam(key string) string {
return w.param[key]
}
func (w *WSConn) SetParam(key string, values interface{}) {
func (w *WSConn) SetParam(key string, values string) {
w.param[key] = values
}