51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
|
package logic
|
||
|
|
||
|
import (
|
||
|
"fusenapi/utils/auth"
|
||
|
"fusenapi/utils/basic"
|
||
|
|
||
|
"context"
|
||
|
|
||
|
"fusenapi/server/websocket/internal/svc"
|
||
|
"fusenapi/server/websocket/internal/types"
|
||
|
|
||
|
"github.com/zeromicro/go-zero/core/logx"
|
||
|
)
|
||
|
|
||
|
type CloseWebsocketLogic struct {
|
||
|
logx.Logger
|
||
|
ctx context.Context
|
||
|
svcCtx *svc.ServiceContext
|
||
|
}
|
||
|
|
||
|
func NewCloseWebsocketLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CloseWebsocketLogic {
|
||
|
return &CloseWebsocketLogic{
|
||
|
Logger: logx.WithContext(ctx),
|
||
|
ctx: ctx,
|
||
|
svcCtx: svcCtx,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 处理进入前逻辑w,r
|
||
|
// func (l *CloseWebsocketLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||
|
// }
|
||
|
|
||
|
func (l *CloseWebsocketLogic) CloseWebsocket(req *types.CloseWebsocketReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||
|
//获取连接
|
||
|
value, ok := mapConnPool.Load(req.Wid)
|
||
|
if !ok {
|
||
|
return resp.SetStatusAddMessage(basic.CodeRequestParamsErr, "wid connection is not exists")
|
||
|
}
|
||
|
ws, ok := value.(wsConnectItem)
|
||
|
if !ok {
|
||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "渲染回调断言websocket连接失败")
|
||
|
}
|
||
|
ws.close()
|
||
|
return resp.SetStatus(basic.CodeOK, "断开成功")
|
||
|
}
|
||
|
|
||
|
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||
|
// func (l *CloseWebsocketLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||
|
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||
|
// }
|