generated from PenaSide/GolangTemplate
Merge branch 'fixLogMW' into 'staging'
Fix log mw See merge request pena-services/customer!55
This commit is contained in:
commit
e6a4341a7b
4
go.mod
4
go.mod
@ -20,9 +20,9 @@ require (
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c
|
||||
google.golang.org/grpc v1.62.0
|
||||
google.golang.org/protobuf v1.33.0
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240202120244-c4ef330cfe5d
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240607142502-8257e6c4aa5a
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240520145524-451212248881
|
||||
penahub.gitlab.yandexcloud.net/external/trashlog.git v0.1.2-0.20240523172059-9bbe8a9faa31
|
||||
penahub.gitlab.yandexcloud.net/external/trashlog.git v0.1.2-0.20240607135420-4279d2c37763
|
||||
)
|
||||
|
||||
require (
|
||||
|
4
go.sum
4
go.sum
@ -321,7 +321,11 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
|
||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240202120244-c4ef330cfe5d h1:gbaDt35HMDqOK84WYmDIlXMI7rstUcRqNttaT6Kx1do=
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240202120244-c4ef330cfe5d/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/backend/quiz/common.git v0.0.0-20240520145524-451212248881 h1:U1/WGQdwZsmrV/ta7Uqm13Dg07IPN/5omS8gzBJYZv4=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240520145524-451212248881/go.mod h1:oRyhT55ctjqp/7ZxIzkR7OsQ7T/NLibsfrbb7Ytns64=
|
||||
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/external/trashlog.git v0.1.2-0.20240607135420-4279d2c37763 h1:fzNg+Cqt2sb5DabtjleFs8mILL+KP8/eBfl7EIP5kBQ=
|
||||
penahub.gitlab.yandexcloud.net/external/trashlog.git v0.1.2-0.20240607135420-4279d2c37763/go.mod h1:3ml0dAGT8U8RhpevKBfRgG6yKZum8EI2uJxAb2WCIy4=
|
||||
|
@ -66,7 +66,7 @@ func Run(config *models.Config, logger *zap.Logger, build Build) (appErr error)
|
||||
|
||||
loggerForHlog := logger.WithOptions(zap.WrapCore(func(core zapcore.Core) zapcore.Core {
|
||||
return zapcore.NewTee(core, clickHouseLogger)
|
||||
}))
|
||||
}), zap.AddCallerSkip(2))
|
||||
|
||||
loggerHlog := hlog.New(loggerForHlog).Module(config.Service.ModuleLogger)
|
||||
loggerHlog.With(models.AllFields{})
|
||||
@ -136,7 +136,7 @@ func Run(config *models.Config, logger *zap.Logger, build Build) (appErr error)
|
||||
Logger: logger,
|
||||
Services: services,
|
||||
Repositories: repositories,
|
||||
HLogger: loggerHlog,
|
||||
HLogger: loggerHlog,
|
||||
})
|
||||
|
||||
encrypt := qutils.NewEncrypt(config.Service.PubKey, config.Service.PrivKey)
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go.uber.org/zap"
|
||||
"math"
|
||||
"penahub.gitlab.yandexcloud.net/backend/penahub_common/log_mw"
|
||||
qutils "penahub.gitlab.yandexcloud.net/backend/quiz/common.git/utils"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/errors"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/client"
|
||||
@ -15,7 +16,6 @@ import (
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/repository"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Deps struct {
|
||||
@ -103,7 +103,7 @@ func (receiver *AccountController) Get(ctx *fiber.Ctx) error {
|
||||
return receiver.middleWare.NoAuth(ctx)
|
||||
}
|
||||
|
||||
hlogger := receiver.middleWare.ExtractLogger(ctx)
|
||||
hlogger := log_mw.ExtractLogger(ctx)
|
||||
|
||||
account, err := receiver.accountRepo.FindByUserID(ctx.Context(), userID)
|
||||
if err != nil {
|
||||
@ -111,10 +111,6 @@ func (receiver *AccountController) Get(ctx *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
hlogger.Emit(models.InfoGetAccount{
|
||||
CtxUserIP: ctx.IP(),
|
||||
CtxUserPort: ctx.Port(),
|
||||
KeyDomain: strings.Join(ctx.Subdomains(), "/"),
|
||||
KeyPath: ctx.Path(),
|
||||
CtxUserID: userID,
|
||||
CtxAccountID: account.ID,
|
||||
})
|
||||
@ -128,7 +124,7 @@ func (receiver *AccountController) Create(ctx *fiber.Ctx) error {
|
||||
return receiver.middleWare.NoAuth(ctx)
|
||||
}
|
||||
|
||||
hlogger := receiver.middleWare.ExtractLogger(ctx)
|
||||
hlogger := log_mw.ExtractLogger(ctx)
|
||||
|
||||
var er error
|
||||
|
||||
@ -167,10 +163,6 @@ func (receiver *AccountController) Create(ctx *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
hlogger.Emit(models.InfoCreateAccount{
|
||||
CtxUserIP: ctx.IP(),
|
||||
CtxUserPort: ctx.Port(),
|
||||
KeyDomain: strings.Join(ctx.Subdomains(), "/"),
|
||||
KeyPath: ctx.Path(),
|
||||
CtxUserID: userID,
|
||||
CtxAccountID: account.ID,
|
||||
KeyFromSource: quiz,
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
"penahub.gitlab.yandexcloud.net/backend/penahub_common/log_mw"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/errors"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/broker/tariff"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/client"
|
||||
@ -84,7 +85,7 @@ func (receiver *CartController) Add2cart(ctx *fiber.Ctx) error {
|
||||
return receiver.middleWare.NoAuth(ctx)
|
||||
}
|
||||
|
||||
hlogger := receiver.middleWare.ExtractLogger(ctx)
|
||||
hlogger := log_mw.ExtractLogger(ctx)
|
||||
|
||||
tariffID := ctx.Query("id")
|
||||
if tariffID == "" {
|
||||
@ -106,10 +107,6 @@ func (receiver *CartController) Add2cart(ctx *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
hlogger.Emit(models.InfoAddToCart{
|
||||
CtxUserIP: ctx.IP(),
|
||||
CtxUserPort: ctx.Port(),
|
||||
KeyDomain: strings.Join(ctx.Subdomains(), "/"),
|
||||
KeyPath: ctx.Path(),
|
||||
CtxUserID: userID,
|
||||
CtxAccountID: cartItems.ID,
|
||||
CtxTariffID: tariffID,
|
||||
@ -129,7 +126,7 @@ func (receiver *CartController) Pay(ctx *fiber.Ctx) error {
|
||||
return receiver.middleWare.NoAuth(ctx)
|
||||
}
|
||||
|
||||
hlogger := receiver.middleWare.ExtractLogger(ctx)
|
||||
hlogger := log_mw.ExtractLogger(ctx)
|
||||
|
||||
account, err := receiver.accountRepo.FindByUserID(ctx.Context(), userID)
|
||||
if err != nil {
|
||||
@ -174,10 +171,6 @@ func (receiver *CartController) Pay(ctx *fiber.Ctx) error {
|
||||
|
||||
if account.Wallet.Money < int64(discountResponse.Price) {
|
||||
hlogger.Emit(models.InfoPayCart{
|
||||
CtxUserIP: ctx.IP(),
|
||||
CtxUserPort: ctx.Port(),
|
||||
KeyDomain: strings.Join(ctx.Subdomains(), "/"),
|
||||
KeyPath: ctx.Path(),
|
||||
CtxUserID: userID,
|
||||
CtxAccountID: account.ID,
|
||||
KeySuccess: false,
|
||||
@ -299,10 +292,6 @@ func (receiver *CartController) Pay(ctx *fiber.Ctx) error {
|
||||
updatedAccount.Cart = []string{}
|
||||
|
||||
hlogger.Emit(models.InfoPayCart{
|
||||
CtxUserIP: ctx.IP(),
|
||||
CtxUserPort: ctx.Port(),
|
||||
KeyDomain: strings.Join(ctx.Subdomains(), "/"),
|
||||
KeyPath: ctx.Path(),
|
||||
CtxUserID: userID,
|
||||
CtxAccountID: updatedAccount.ID,
|
||||
KeySuccess: true,
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"go.uber.org/zap"
|
||||
"math"
|
||||
"os"
|
||||
"penahub.gitlab.yandexcloud.net/backend/penahub_common/log_mw"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/client"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/controller/http"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/repository"
|
||||
@ -166,7 +167,7 @@ func (receiver *HistoryController) GetRecentTariffs(ctx *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
func (receiver *HistoryController) SendReport(ctx *fiber.Ctx) error {
|
||||
hlogger := receiver.middleWare.ExtractLogger(ctx)
|
||||
hlogger := log_mw.ExtractLogger(ctx)
|
||||
|
||||
var req struct {
|
||||
Id string `json:"id"`
|
||||
@ -284,10 +285,6 @@ func (receiver *HistoryController) SendReport(ctx *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
hlogger.Emit(models.InfoReportRequest{
|
||||
CtxUserIP: ctx.IP(),
|
||||
CtxUserPort: ctx.Port(),
|
||||
KeyDomain: strings.Join(ctx.Subdomains(), "/"),
|
||||
KeyPath: ctx.Path(),
|
||||
CtxUserID: tariffs.UserID,
|
||||
CtxAccountID: account.ID,
|
||||
CtxID: req.Id,
|
||||
|
@ -3,7 +3,6 @@ package http
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/themakers/hlog"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models"
|
||||
)
|
||||
@ -54,8 +53,3 @@ func (mw *MiddleWare) ExtractToken(ctx *fiber.Ctx) (string, bool) {
|
||||
func (mw *MiddleWare) GetHealth(ctx *fiber.Ctx) error {
|
||||
return ctx.Status(fiber.StatusOK).SendString("OK")
|
||||
}
|
||||
|
||||
func (mw *MiddleWare) ExtractLogger(ctx *fiber.Ctx) hlog.Logger {
|
||||
logger := ctx.Context().UserValue(models.LoggerKey).(hlog.Logger)
|
||||
return logger
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/backend/penahub_common/log_mw"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/errors"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/client"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/controller/http"
|
||||
@ -13,7 +14,6 @@ import (
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/proto/treasurer"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/utils"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/pkg/validate"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Deps struct {
|
||||
@ -60,7 +60,7 @@ func (receiver *WalletController) RequestMoney(ctx *fiber.Ctx) error {
|
||||
return receiver.middleWare.NoAuth(ctx)
|
||||
}
|
||||
|
||||
hlogger := receiver.middleWare.ExtractLogger(ctx)
|
||||
hlogger := log_mw.ExtractLogger(ctx)
|
||||
|
||||
var request models.GetPaymentLinkBody
|
||||
if err := ctx.BodyParser(&request); err != nil {
|
||||
@ -71,6 +71,11 @@ func (receiver *WalletController) RequestMoney(ctx *fiber.Ctx) error {
|
||||
return receiver.middleWare.ErrorOld(ctx, err)
|
||||
}
|
||||
|
||||
account, err := receiver.accountRepo.FindByUserID(ctx.Context(), userID)
|
||||
if err != nil {
|
||||
return receiver.middleWare.ErrorOld(ctx, err)
|
||||
}
|
||||
|
||||
link, err := receiver.GetPaymentLink(ctx.Context(), &models.GetPaymentLinkRequest{
|
||||
Body: &request,
|
||||
UserID: userID,
|
||||
@ -81,16 +86,11 @@ func (receiver *WalletController) RequestMoney(ctx *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
hlogger.Emit(models.InfoRequestMoney{
|
||||
CtxUserIP: ctx.IP(),
|
||||
CtxUserPort: ctx.Port(),
|
||||
KeyDomain: strings.Join(ctx.Subdomains(), "/"),
|
||||
KeyPath: ctx.Path(),
|
||||
CtxUserID: userID,
|
||||
// todo
|
||||
CtxAccountID: "",
|
||||
CtxUserID: userID,
|
||||
CtxAccountID: account.ID,
|
||||
KeyPaymentType: string(request.Type),
|
||||
KeyCurrency: request.Currency,
|
||||
CtxPrice: int64(request.Amount),
|
||||
CtxPrice: request.Amount,
|
||||
CtxReturnURL: link,
|
||||
})
|
||||
|
||||
@ -287,7 +287,7 @@ func (receiver *WalletController) PostWalletRspay(ctx *fiber.Ctx) error {
|
||||
return receiver.middleWare.NoAuth(ctx)
|
||||
}
|
||||
|
||||
hlogger := receiver.middleWare.ExtractLogger(ctx)
|
||||
hlogger := log_mw.ExtractLogger(ctx)
|
||||
|
||||
var req struct {
|
||||
Money *float32 `json:"money,omitempty"`
|
||||
@ -330,10 +330,6 @@ func (receiver *WalletController) PostWalletRspay(ctx *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
hlogger.Emit(models.InfoRSPay{
|
||||
CtxUserIP: ctx.IP(),
|
||||
CtxUserPort: ctx.Port(),
|
||||
KeyDomain: strings.Join(ctx.Subdomains(), "/"),
|
||||
KeyPath: ctx.Path(),
|
||||
CtxUserID: userID,
|
||||
CtxAccountID: user.ID,
|
||||
CtxPrice: int64(*req.Money),
|
||||
|
@ -15,4 +15,3 @@ type User struct {
|
||||
|
||||
const AuthJWTDecodedUserIDKey = "userID"
|
||||
const AuthJWTDecodedAccessTokenKey = "access-token"
|
||||
const LoggerKey = "logger"
|
||||
|
@ -28,10 +28,6 @@ type AllFields struct {
|
||||
}
|
||||
|
||||
type InfoCreateAccount struct {
|
||||
CtxUserIP string
|
||||
CtxUserPort string
|
||||
KeyDomain string
|
||||
KeyPath string
|
||||
CtxUserID string //айдишник юзера из токена
|
||||
KeyFromSource string //метка, откуда пришел пользователь. если куки quizFrom не пустые, ставить quiz
|
||||
KeyFromID string //значение той куки, quizFrom
|
||||
@ -43,65 +39,45 @@ type InfoCreateAccount struct {
|
||||
}
|
||||
|
||||
type InfoGetAccount struct {
|
||||
CtxUserIP string
|
||||
CtxUserPort string
|
||||
KeyDomain string
|
||||
KeyPath string
|
||||
CtxUserID string //айдишник юзера из токена
|
||||
CtxAccountID string // айдишник аккаунта
|
||||
}
|
||||
|
||||
type InfoAddToCart struct {
|
||||
CtxUserIP string
|
||||
CtxUserPort string
|
||||
KeyDomain string
|
||||
KeyPath string
|
||||
CtxUserID string //айдишник юзера из токена
|
||||
CtxAccountID string // айдишник аккаунта
|
||||
CtxTariffID string //айдишник тарифа, добавленного в корзину
|
||||
}
|
||||
|
||||
type InfoPayCart struct {
|
||||
CtxUserIP string
|
||||
CtxUserPort string
|
||||
KeyDomain string
|
||||
KeyPath string
|
||||
CtxUserID string //айдишник юзера из токена
|
||||
CtxAccountID string // айдишник аккаунта
|
||||
KeySuccess bool // получилось оплатить или не хватило денег
|
||||
CtxPrice int64 // сумма в копейках. если не удалось оплатить - записать сколько денег не хватило
|
||||
CtxPrice int64 // сумма в копейках. если не удалось оплатить - записать сколько денег не хватило
|
||||
CtxTariff string // через запятую список покупаемых тарифов
|
||||
CtxDiscount string // через запятую список применённых скидок
|
||||
CtxRowPrice int64 // стоимость без скидок
|
||||
CtxRowPrice int64 // стоимость без скидок
|
||||
CtxRowData string // замаршаленные данные, которые обычно складываются в RawDetails
|
||||
}
|
||||
|
||||
type InfoRequestMoney struct {
|
||||
CtxUserIP string
|
||||
CtxUserPort string
|
||||
KeyDomain string
|
||||
KeyPath string
|
||||
CtxUserID string //айдишник юзера из токена
|
||||
CtxAccountID string // айдишник аккаунта
|
||||
KeyPaymentType string //направление оплаты, через которое оплачиваем
|
||||
KeyCurrency string //значение валюты кошелька. сейчас там фиксированное, но потом пригодится
|
||||
CtxPrice int64 // сумма в копейках
|
||||
CtxPrice int64 // сумма в копейках
|
||||
CtxReturnURL string // возвращенный от аггрегатора линк на оплату
|
||||
}
|
||||
|
||||
type InfoMoneyIncome struct {
|
||||
CtxUserID string //айдишник юзера из токена
|
||||
CtxPrice int64 // сумма в копейках
|
||||
CtxPrice int64 // сумма в копейках
|
||||
KeyCurrency string //значение валюты кошелька. сейчас там фиксированное, но потом пригодится
|
||||
CtxID string //айдишник запроса оплаты
|
||||
KeyPaymentType string //направление оплаты, через которое оплачиваем
|
||||
}
|
||||
|
||||
type InfoReportRequest struct {
|
||||
CtxUserIP string
|
||||
CtxUserPort string
|
||||
KeyDomain string
|
||||
KeyPath string
|
||||
CtxUserID string //айдишник юзера из токена
|
||||
CtxAccountID string // айдишник аккаунта
|
||||
CtxID string //айдишник истории, по которой создаётся акт
|
||||
@ -110,12 +86,8 @@ type InfoReportRequest struct {
|
||||
}
|
||||
|
||||
type InfoRSPay struct {
|
||||
CtxUserIP string
|
||||
CtxUserPort string
|
||||
KeyDomain string
|
||||
KeyPath string
|
||||
CtxUserID string //айдишник юзера из токена
|
||||
CtxAccountID string // айдишник аккаунта
|
||||
CtxPrice int64 // сумма в копейках
|
||||
CtxPrice int64 // сумма в копейках
|
||||
CtxLogin string // значение логина. мы там получаем его из сервиса авторизации
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/themakers/hlog"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/backend/penahub_common/log_mw"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/utils"
|
||||
)
|
||||
@ -29,7 +30,7 @@ func NewServer(config ServerConfig) *Server {
|
||||
|
||||
jwtUtil := utils.NewJWT(config.JWTConfig)
|
||||
app.Use(utils.NewAuthenticator(jwtUtil))
|
||||
app.Use(utils.ContextLogger(config.Hlog))
|
||||
app.Use(log_mw.ContextLogger(config.Hlog))
|
||||
|
||||
s := &Server{
|
||||
Logger: config.Logger,
|
||||
|
@ -1,14 +0,0 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/themakers/hlog"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models"
|
||||
)
|
||||
|
||||
func ContextLogger(logger hlog.Logger) fiber.Handler {
|
||||
return func(c *fiber.Ctx) error {
|
||||
c.Locals(models.LoggerKey, logger)
|
||||
return c.Next()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user