This commit is contained in:
laodaming 2023-08-18 16:03:29 +08:00
parent a19d526e72
commit 04982bae18

View File

@ -80,6 +80,9 @@ type wsConnectItem struct {
}
func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request) {
token := r.Header.Get("Sec-Websocket-Protocol")
//设置Sec-Websocket-Protocol
upgrade.Subprotocols = []string{token}
//升级websocket
conn, err := upgrade.Upgrade(w, r, nil)
if err != nil {
@ -88,10 +91,11 @@ func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request)
}
defer conn.Close()
//鉴权不成功后断开
/*var (
var (
userInfo *auth.UserInfo
isAuth bool
)
fmt.Println("###################:", r.Header)
isAuth, userInfo = l.checkAuth(r)
if !isAuth {
time.Sleep(time.Second * 1) //兼容下火狐
@ -105,12 +109,12 @@ func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request)
//发送关闭信息
_ = conn.WriteMessage(websocket.CloseMessage, nil)
return
}*/
}
// todo user信息是没有的
var userInfo auth.UserInfo
userInfo.UserId = 39
/*var userInfo auth.UserInfo
userInfo.UserId = 39*/
//设置连接
ws := l.setConnPool(conn, userInfo)
ws := l.setConnPool(conn, *userInfo)
defer ws.close()
//循环读客户端信息
go ws.readLoop()