This commit is contained in:
laodaming 2023-08-16 14:16:33 +08:00
parent 7bdd1f00af
commit 7d2c2ab025
2 changed files with 5 additions and 5 deletions

View File

@ -10,6 +10,6 @@ func DataTransferHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// 创建一个业务逻辑层实例
l := logic.NewDataTransferLogic(r.Context(), svcCtx)
l.DataTransfer(svcCtx, w, r)
l.DataTransfer(w, r)
}
}

View File

@ -79,7 +79,7 @@ type wsConnectItem struct {
renderProperty renderProperty //扩展云渲染属性
}
func (l *DataTransferLogic) DataTransfer(svcCtx *svc.ServiceContext, w http.ResponseWriter, r *http.Request) {
func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request) {
//升级websocket
conn, err := upgrade.Upgrade(w, r, nil)
if err != nil {
@ -92,7 +92,7 @@ func (l *DataTransferLogic) DataTransfer(svcCtx *svc.ServiceContext, w http.Resp
userInfo *auth.UserInfo
isAuth bool
)
isAuth, userInfo = l.checkAuth(svcCtx, r)
isAuth, userInfo = l.checkAuth(r)
if !isAuth {
time.Sleep(time.Second * 1) //兼容下火狐
rsp := websocket_data.DataTransferData{
@ -170,9 +170,9 @@ func getUserPart(userId, guestId int64) string {
}
// 鉴权
func (l *DataTransferLogic) checkAuth(svcCtx *svc.ServiceContext, r *http.Request) (isAuth bool, userInfo *auth.UserInfo) {
func (l *DataTransferLogic) checkAuth(r *http.Request) (isAuth bool, userInfo *auth.UserInfo) {
// 解析JWT token,并对空用户进行判断
claims, err := svcCtx.ParseJwtToken(r)
claims, err := l.svcCtx.ParseJwtToken(r)
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
if err != nil {
return false, nil