feat: custom json marshaling implementation, replace json and yaml library (#89)

* chore: replace gopkg.in/yaml.v3 vs goccy/go-yaml; replace encoding/json with bytedance/sonic

* fix: yaml unmarshal panic

* feat: custom json marshaler implementation

* chore: fix import and err marshal handling

---------

Co-authored-by: yusing <yusing@6uo.me>
This commit is contained in:
Yuzerion
2025-04-16 15:02:11 +08:00
committed by GitHub
parent 57292f0fe8
commit 80bc018a7f
65 changed files with 1749 additions and 205 deletions

View File

@@ -2,7 +2,8 @@ package notif
import (
"bytes"
"encoding/json"
"github.com/yusing/go-proxy/pkg/json"
)
func formatMarkdown(extras LogFields) string {

View File

@@ -2,11 +2,12 @@ package notif
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"github.com/yusing/go-proxy/pkg/json"
"github.com/gotify/server/v2/model"
"github.com/rs/zerolog"
)

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,
)