refactor(log): consolidate logging models and update related logic for improved clarity and functionality

This commit is contained in:
Chang lue Tsen
2025-08-20 13:36:06 -04:00
parent 4f32d67113
commit 87c771bbd4
41 changed files with 1082 additions and 707 deletions
+6 -27
View File
@@ -1,11 +1,9 @@
package common
import (
"bytes"
"context"
"encoding/json"
"fmt"
"text/template"
"time"
"github.com/hibiken/asynq"
@@ -90,12 +88,13 @@ func (l *SendEmailCodeLogic) SendEmailCode(req *types.SendCodeRequest) (resp *ty
code := random.Key(6, 0)
taskPayload.Email = req.Email
taskPayload.Subject = "Verification code"
content, err := l.initTemplate(req.Type, code)
if err != nil {
l.Logger.Error("[SendEmailCode]: InitTemplate Error", logger.Field("error", err.Error()))
return nil, errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "Failed to init template")
taskPayload.Content = map[string]interface{}{
"Type": req.Type,
"SiteLogo": l.svcCtx.Config.Site.SiteLogo,
"SiteName": l.svcCtx.Config.Site.SiteName,
"Expire": 5,
"Code": code,
}
taskPayload.Content = content
// Save to Redis
payload = CacheKeyPayload{
Code: code,
@@ -134,23 +133,3 @@ func (l *SendEmailCodeLogic) SendEmailCode(req *types.SendCodeRequest) (resp *ty
}, nil
}
}
func (l *SendEmailCodeLogic) initTemplate(t uint8, code string) (string, error) {
data := VerifyTemplate{
Type: t,
SiteLogo: l.svcCtx.Config.Site.SiteLogo,
SiteName: l.svcCtx.Config.Site.SiteName,
Expire: 5,
Code: code,
}
tpl, err := template.New("verify").Parse(l.svcCtx.Config.Email.VerifyEmailTemplate)
if err != nil {
return "", err
}
var result bytes.Buffer
err = tpl.Execute(&result, data)
if err != nil {
return "", err
}
return result.String(), nil
}