diff --git a/server/websocket/internal/logic/getstatlogic.go b/server/websocket/internal/logic/getstatlogic.go index 7aaac9c1..ab95fd05 100644 --- a/server/websocket/internal/logic/getstatlogic.go +++ b/server/websocket/internal/logic/getstatlogic.go @@ -4,6 +4,7 @@ import ( "context" "fusenapi/utils/auth" "fusenapi/utils/basic" + "strings" "sync" "fusenapi/server/websocket/internal/svc" @@ -42,23 +43,10 @@ func (l *GetStatLogic) GetStat(req *types.GetStatReq, userinfo *auth.UserInfo) ( currentCombineApiCount := 0 currentUnityHandleCount := 0 combineErrorCount := 0 - lenUserList := len(req.UserKey) - switch lenUserList { - case 0: //遍历所有 - mapUserWsStat.Range(func(key, value any) bool { - if stat, ok := value.(mapUserWsStatItem); ok { - currentWebsocketConnectCount += stat.CurWsConnectCount - currentCombineApiCount += stat.CurCombineCount - currentUnityHandleCount += stat.CurUnityHandleCount - combineErrorCount += stat.CombineErrCount - } else { - logx.Error("断言mapUserWsStatItem错误") - } - userStat[key.(string)] = value - return true - }) - default: //有指定用户 - for _, key := range req.UserKey { + req.UserKeys = strings.Trim(req.UserKeys, " ") + if req.UserKeys != "" { //指定用户群体 + reqUserList := strings.Split(req.UserKeys, ",") + for _, key := range reqUserList { value, ok := mapUserWsStat.Load(key) if ok { //存在就累加 if stat, ok := value.(mapUserWsStatItem); ok { @@ -72,8 +60,20 @@ func (l *GetStatLogic) GetStat(req *types.GetStatReq, userinfo *auth.UserInfo) ( } userStat[key] = mapUserWsStatItem{} } + } else { //不指定用户 + mapUserWsStat.Range(func(key, value any) bool { + if stat, ok := value.(mapUserWsStatItem); ok { + currentWebsocketConnectCount += stat.CurWsConnectCount + currentCombineApiCount += stat.CurCombineCount + currentUnityHandleCount += stat.CurUnityHandleCount + combineErrorCount += stat.CombineErrCount + } else { + logx.Error("断言mapUserWsStatItem错误") + } + userStat[key.(string)] = value + return true + }) } - return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetStatRsp{ WsTotalCount: currentWebsocketConnectCount, CurCombineCount: currentCombineApiCount, diff --git a/server/websocket/internal/types/types.go b/server/websocket/internal/types/types.go index 397eb9fa..65323aa2 100644 --- a/server/websocket/internal/types/types.go +++ b/server/websocket/internal/types/types.go @@ -30,8 +30,8 @@ type CloseWebsocketReq struct { } type GetStatReq struct { - Password string `form:"password"` - UserKey []string `form:"user_key,optional"` + Password string `form:"password"` + UserKeys string `form:"user_keys,optional"` } type GetStatRsp struct { diff --git a/server_api/websocket.api b/server_api/websocket.api index 4b8bddd7..5c5fe781 100644 --- a/server_api/websocket.api +++ b/server_api/websocket.api @@ -52,8 +52,8 @@ type CloseWebsocketReq { } //获取ws统计信息 type GetStatReq { - Password string `form:"password"` - UserKey []string `form:"user_key,optional"` + Password string `form:"password"` + UserKeys string `form:"user_keys,optional"` } type GetStatRsp { WsTotalCount int `json:"ws_total_count"` //ws连接总数