From 78bf3a782798ea007b5be30eaf4b109a45ed5e5f Mon Sep 17 00:00:00 2001 From: zhaoxiaorong Date: Fri, 7 Feb 2025 17:09:59 +0800 Subject: [PATCH] fix --- infra/parser.go | 20 -------------- infra/response.go | 69 ----------------------------------------------- 2 files changed, 89 deletions(-) delete mode 100644 infra/parser.go delete mode 100644 infra/response.go diff --git a/infra/parser.go b/infra/parser.go deleted file mode 100644 index 220a798..0000000 --- a/infra/parser.go +++ /dev/null @@ -1,20 +0,0 @@ -package infra - -import ( - "github.com/gofiber/fiber/v2" -) - -type Auth struct { - CustomerID int64 // 企业编号 - CustomerCode string // 企业标识 - UserID int64 // 用户编号 - UserIdentity string // 用户标识 -} - -func ParserCtx(ctx *fiber.Ctx) *Auth { - customerID := ctx.Locals("customerID").(int64) - customerCode := ctx.Locals("customerCode").(string) - userID := ctx.Locals("userID").(int64) - userIdentity := ctx.Locals("userIdentity").(string) - return &Auth{CustomerID: customerID, CustomerCode: customerCode, UserID: userID, UserIdentity: userIdentity} -} diff --git a/infra/response.go b/infra/response.go deleted file mode 100644 index cfbd47e..0000000 --- a/infra/response.go +++ /dev/null @@ -1,69 +0,0 @@ -package infra - -import ( - "net/http" - "time" - - "git.apinb.com/bsm-sdk/core/vars" - "github.com/gofiber/fiber/v2" -) - -var Response Reply - -type Reply struct { - Ret int `json:"ret"` - Msg string `json:"msg"` - Data interface{} `json:"data"` -} - -type ReplyIdent struct { - ID uint `json:"id"` - Identiy string `json:"identity"` -} - -func (r *Reply) Error(ctx *fiber.Ctx, err error) error { - // Status code defaults to 500 - reply := Reply{ - Ret: http.StatusInternalServerError, - } - if e, ok := err.(*fiber.Error); ok { - reply.Ret = e.Code - } - - // 获取执行信息 - ExcuteTime(ctx) - - reply.Msg = err.Error() - - // Send error - return ctx.Status(fiber.StatusInternalServerError).JSON(reply) -} -func (r *Reply) Success(ctx *fiber.Ctx, data interface{}) error { - reply := Reply{ - Ret: http.StatusOK, - } - - if data == nil { - reply.Data = "" - } else { - reply.Data = data - } - - // 获取执行信息 - ExcuteTime(ctx) - - return ctx.Status(fiber.StatusOK).JSON(reply) -} - -func ExcuteTime(ctx *fiber.Ctx) error { - // 从context中获取开始时间 - startTime, ok := ctx.Locals("startTime").(time.Time) - if !ok { - // 如果转换失败,则默认为当前时间 - startTime = time.Now() - } - - exectime := time.Since(startTime) - ctx.Response().Header.Add("Execute-Node", vars.HostName+","+exectime.String()) - return nil -}