From bbb050566212a7d0d98dde750ebdacc71af1e23a Mon Sep 17 00:00:00 2001 From: Pavel Date: Fri, 7 Jun 2024 17:33:07 +0300 Subject: [PATCH] delete base user log data and movw mw to common pj --- go.mod | 2 +- go.sum | 2 ++ .../controllers/admin/verification_admin.go | 19 ++++----------- .../controllers/user/verification_user.go | 23 ++++++------------- internal/models/events_hlog.go | 22 ++++-------------- internal/models/validate.go | 1 - internal/server/http.go | 3 ++- internal/server/middleware.go | 8 ------- 8 files changed, 22 insertions(+), 58 deletions(-) diff --git a/go.mod b/go.mod index ca978f3..490de41 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/themakers/hlog v0.0.0-20191205140925-235e0e4baddf go.mongodb.org/mongo-driver v1.14.0 go.uber.org/zap v1.27.0 - penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240527160654-bd1c2126bc6c + penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240607142502-8257e6c4aa5a penahub.gitlab.yandexcloud.net/external/trashlog.git v0.1.2-0.20240523172059-9bbe8a9faa31 penahub.gitlab.yandexcloud.net/pena-services/customer v1.0.1-0.20240526134522-aab18dfcec46 ) diff --git a/go.sum b/go.sum index 62aed22..b66873d 100644 --- a/go.sum +++ b/go.sum @@ -245,6 +245,8 @@ penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240527155320-a234 penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240527155320-a234eec54383/go.mod h1:lTmpjry+8evVkXWbEC+WMOELcFkRD1lFMc7J09mOndM= penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240527160654-bd1c2126bc6c h1:jxnyIeC2CNDNmfdFx2qnLS4Qd0v5ocYrY9X+OL9qsvc= penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240527160654-bd1c2126bc6c/go.mod h1:lTmpjry+8evVkXWbEC+WMOELcFkRD1lFMc7J09mOndM= +penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240607142502-8257e6c4aa5a h1:dGW8ErUVdwGJBq6uc5AHYn6Yt10CDNkMIpV+yrDDTLs= +penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240607142502-8257e6c4aa5a/go.mod h1:+bPxq2wfW5S1gd+83vZYmHm33AE7nEBfznWS8AM1TKE= penahub.gitlab.yandexcloud.net/external/trashlog.git v0.1.2-0.20240523172059-9bbe8a9faa31 h1:WlRVJnzU0sti+qBq/JTCgFPU0RoxIqGHu7hzDirxE2k= penahub.gitlab.yandexcloud.net/external/trashlog.git v0.1.2-0.20240523172059-9bbe8a9faa31/go.mod h1:3ml0dAGT8U8RhpevKBfRgG6yKZum8EI2uJxAb2WCIy4= penahub.gitlab.yandexcloud.net/pena-services/customer v1.0.1-0.20240526134522-aab18dfcec46 h1:AX5HxEjjOf6YajMmi2vAB8hErBGEGouPB8ei9VVmdmo= diff --git a/internal/controllers/admin/verification_admin.go b/internal/controllers/admin/verification_admin.go index 189b344..60f3b29 100644 --- a/internal/controllers/admin/verification_admin.go +++ b/internal/controllers/admin/verification_admin.go @@ -2,12 +2,11 @@ package admin import ( "github.com/gofiber/fiber/v2" - "github.com/themakers/hlog" + "penahub.gitlab.yandexcloud.net/backend/penahub_common/log_mw" "penahub.gitlab.yandexcloud.net/backend/verification/internal/models" "penahub.gitlab.yandexcloud.net/backend/verification/internal/repository" "penahub.gitlab.yandexcloud.net/backend/verification/pkg/validate_controllers" "penahub.gitlab.yandexcloud.net/pena-services/customer/pkg/customer_clients" - "strings" ) type VerifyAdminControllerDeps struct { @@ -29,7 +28,7 @@ func NewVerificationAdminController(deps VerifyAdminControllerDeps) *VerifyAdmin func (r *VerifyAdminController) SetVerificationStatus(c *fiber.Ctx) error { var req models.ReqSetVerification - hloger := c.Locals(models.HlogCtxKey).(hlog.Logger) + hloger := log_mw.ExtractLogger(c) err := c.BodyParser(&req) if err != nil { return fiber.NewError(fiber.StatusBadRequest, err.Error()) @@ -58,10 +57,6 @@ func (r *VerifyAdminController) SetVerificationStatus(c *fiber.Ctx) error { } hloger.Emit(models.InfoVerificationAccepted{ - CtxUserIP: c.IP(), - CtxUserPort: c.Port(), - KeyDomain: strings.Join(c.Subdomains(), "/"), - KeyPath: c.Path(), CtxID: updated.ID, KeyStatus: updated.Status, CtxTaxNumber: updated.TaxNumber, @@ -70,13 +65,9 @@ func (r *VerifyAdminController) SetVerificationStatus(c *fiber.Ctx) error { if !req.Accepted { hloger.Emit(models.InfoVerificationDeclined{ - CtxUserIP: c.IP(), - CtxUserPort: c.Port(), - KeyDomain: strings.Join(c.Subdomains(), "/"), - KeyPath: c.Path(), - CtxID: updated.ID, - KeyStatus: updated.Status, - CtxComment: updated.Comment, + CtxID: updated.ID, + KeyStatus: updated.Status, + CtxComment: updated.Comment, }) } diff --git a/internal/controllers/user/verification_user.go b/internal/controllers/user/verification_user.go index a5068e2..c621406 100644 --- a/internal/controllers/user/verification_user.go +++ b/internal/controllers/user/verification_user.go @@ -3,14 +3,13 @@ package user import ( "errors" "github.com/gofiber/fiber/v2" - "github.com/themakers/hlog" "github.com/valyala/fasthttp" "mime/multipart" + "penahub.gitlab.yandexcloud.net/backend/penahub_common/log_mw" "penahub.gitlab.yandexcloud.net/backend/verification/internal/client" "penahub.gitlab.yandexcloud.net/backend/verification/internal/models" "penahub.gitlab.yandexcloud.net/backend/verification/internal/repository" "penahub.gitlab.yandexcloud.net/backend/verification/pkg/validate_controllers" - "strings" ) type VerifyUserControllerDeps struct { @@ -51,7 +50,7 @@ func (r *VerifyUserController) GetVerification(c *fiber.Ctx) error { func (r *VerifyUserController) CreateVerification(c *fiber.Ctx) error { var req models.ReqCreateVerification baseURL := c.BaseURL() - hloger := c.Locals(models.HlogCtxKey).(hlog.Logger) + hloger := log_mw.ExtractLogger(c) userID := c.Locals(models.UserCtxKey).(string) if userID == "" { @@ -116,12 +115,8 @@ func (r *VerifyUserController) CreateVerification(c *fiber.Ctx) error { } hloger.Emit(models.InfoVerificationRequested{ - CtxUserIP: c.IP(), - CtxUserPort: c.Port(), - KeyDomain: strings.Join(c.Subdomains(), "/"), - KeyPath: c.Path(), - CtxID: result.ID, - KeyStatus: result.Status, + CtxID: result.ID, + KeyStatus: result.Status, }) return c.Status(fiber.StatusOK).JSON(result) @@ -129,7 +124,7 @@ func (r *VerifyUserController) CreateVerification(c *fiber.Ctx) error { func (r *VerifyUserController) SetVerificationFile(c *fiber.Ctx) error { baseURL := c.BaseURL() - hloger := c.Locals(models.HlogCtxKey).(hlog.Logger) + hloger := log_mw.ExtractLogger(c) userID := c.Locals(models.UserCtxKey).(string) if userID == "" { @@ -164,12 +159,8 @@ func (r *VerifyUserController) SetVerificationFile(c *fiber.Ctx) error { } hloger.Emit(models.InfoVerificationRequested{ - CtxUserIP: c.IP(), - CtxUserPort: c.Port(), - KeyDomain: strings.Join(c.Subdomains(), "/"), - KeyPath: c.Path(), - CtxID: result.ID, - KeyStatus: result.Status, + CtxID: result.ID, + KeyStatus: result.Status, }) return c.SendStatus(fiber.StatusOK) diff --git a/internal/models/events_hlog.go b/internal/models/events_hlog.go index ba6fdf0..b1b1526 100644 --- a/internal/models/events_hlog.go +++ b/internal/models/events_hlog.go @@ -12,27 +12,15 @@ type AllFields struct { } type InfoVerificationRequested struct { //эмиттить при подаче на верификацию и при замене файла - CtxUserIP string - CtxUserPort string - KeyDomain string - KeyPath string - CtxID string // - айдишник верификации - KeyStatus string // статус, который пользователь хочет обрести после верификации + CtxID string // - айдишник верификации + KeyStatus string // статус, который пользователь хочет обрести после верификации } type InfoVerificationDeclined struct { - CtxUserIP string - CtxUserPort string - KeyDomain string - KeyPath string - CtxID string // - айдишник верификации - KeyStatus string // статус, который пользователь хочет обрести после верификации - CtxComment string // комментарий при отклонении + CtxID string // - айдишник верификации + KeyStatus string // статус, который пользователь хочет обрести после верификации + CtxComment string // комментарий при отклонении } type InfoVerificationAccepted struct { - CtxUserIP string - CtxUserPort string - KeyDomain string - KeyPath string CtxID string // - айдишник верификации KeyStatus string // статус, который пользователь хочет обрести после верификации CtxTaxNumber string diff --git a/internal/models/validate.go b/internal/models/validate.go index f1fadff..50216fd 100644 --- a/internal/models/validate.go +++ b/internal/models/validate.go @@ -8,4 +8,3 @@ type RespErrorValidate struct { const UserCtxKey = "userID" const TokenCtxKey = "token" -const HlogCtxKey = "logger" diff --git a/internal/server/http.go b/internal/server/http.go index 162afb9..4192838 100644 --- a/internal/server/http.go +++ b/internal/server/http.go @@ -8,6 +8,7 @@ import ( "github.com/gofiber/fiber/v2/middleware/recover" "github.com/themakers/hlog" "go.uber.org/zap" + "penahub.gitlab.yandexcloud.net/backend/penahub_common/log_mw" ) type ServerConfig struct { @@ -34,7 +35,7 @@ func NewHTTP(cfg ServerConfig) *Server { fiberzap.New(fiberzap.Config{Logger: cfg.Logger}), LocalJwt(), Jwt(), - ContextLogger(cfg.HLogger), + log_mw.ContextLogger(cfg.HLogger), ) s := &Server{ diff --git a/internal/server/middleware.go b/internal/server/middleware.go index c2d846a..69a5191 100644 --- a/internal/server/middleware.go +++ b/internal/server/middleware.go @@ -1,7 +1,6 @@ package server import ( - "github.com/themakers/hlog" "penahub.gitlab.yandexcloud.net/backend/verification/internal/models" "strings" @@ -45,10 +44,3 @@ func Jwt() fiber.Handler { return c.Next() } } - -func ContextLogger(logger hlog.Logger) fiber.Handler { - return func(c *fiber.Ctx) error { - c.Locals(models.HlogCtxKey, logger) - return c.Next() - } -}