refactor: refactor to adapt new custom json marshaler

This commit is contained in:
yusing
2025-04-16 14:39:26 +08:00
parent cdfc9d553b
commit c2b606e63e
43 changed files with 232 additions and 189 deletions

View File

@@ -2,12 +2,13 @@ package notif
import (
_ "embed"
"encoding/json"
"fmt"
"io"
"net/http"
"strings"
"github.com/yusing/go-proxy/pkg/json"
"github.com/yusing/go-proxy/internal/gperr"
)
@@ -101,10 +102,7 @@ func (webhook *Webhook) makeRespError(resp *http.Response) error {
}
func (webhook *Webhook) MakeBody(logMsg *LogMessage) (io.Reader, error) {
title, err := json.Marshal(logMsg.Title)
if err != nil {
return nil, err
}
title := json.String(logMsg.Title)
fields, err := formatDiscord(logMsg.Extras)
if err != nil {
return nil, err
@@ -115,13 +113,10 @@ func (webhook *Webhook) MakeBody(logMsg *LogMessage) (io.Reader, error) {
} else {
color = logMsg.Color.DecString()
}
message, err := json.Marshal(formatMarkdown(logMsg.Extras))
if err != nil {
return nil, err
}
message := json.String(formatMarkdown(logMsg.Extras))
plTempl := strings.NewReplacer(
"$title", string(title),
"$message", string(message),
"$title", title,
"$message", message,
"$fields", fields,
"$color", color,
)