From 65f7e1bee4232960a88e27f573d7906c0a9f605b Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 20 Oct 2023 15:14:48 +0800 Subject: [PATCH] fix --- .../internal/handler/getstathandler.go | 35 +++++++++++++++ .../websocket/internal/logic/getstatlogic.go | 45 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 server/websocket/internal/handler/getstathandler.go create mode 100644 server/websocket/internal/logic/getstatlogic.go diff --git a/server/websocket/internal/handler/getstathandler.go b/server/websocket/internal/handler/getstathandler.go new file mode 100644 index 00000000..3e38aa95 --- /dev/null +++ b/server/websocket/internal/handler/getstathandler.go @@ -0,0 +1,35 @@ +package handler + +import ( + "net/http" + "reflect" + + "fusenapi/utils/basic" + + "fusenapi/server/websocket/internal/logic" + "fusenapi/server/websocket/internal/svc" + "fusenapi/server/websocket/internal/types" +) + +func GetStatHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + + var req types.GetStatReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } + + // 创建一个业务逻辑层实例 + l := logic.NewGetStatLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.GetStat(&req, userinfo) + + if !basic.AfterLogic(w, r, rl, resp) { + basic.NormalAfterLogic(w, r, resp) + } + } +} diff --git a/server/websocket/internal/logic/getstatlogic.go b/server/websocket/internal/logic/getstatlogic.go new file mode 100644 index 00000000..b36029ee --- /dev/null +++ b/server/websocket/internal/logic/getstatlogic.go @@ -0,0 +1,45 @@ +package logic + +import ( + "context" + "fusenapi/utils/auth" + "fusenapi/utils/basic" + + "fusenapi/server/websocket/internal/svc" + "fusenapi/server/websocket/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetStatLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewGetStatLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetStatLogic { + return &GetStatLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +// 处理进入前逻辑w,r +// func (l *GetStatLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// } + +func (l *GetStatLogic) GetStat(req *types.GetStatReq, userinfo *auth.UserInfo) (resp *basic.Response) { + if req.Password != "fusen1314" { + return resp.SetStatusWithMessage(basic.CodeOK, "你干嘛,哎哟") + } + return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetStatRsp{ + WsTotalCount: currentWebsocketConnectCount, + CurRequestCombineCount: currentRequestCombineApiCount, + }) +} + +// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 +// func (l *GetStatLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// // httpx.OkJsonCtx(r.Context(), w, resp) +// }