feat(json): improve JSON performance with bytedance/sonic

This commit is contained in:
yusing
2025-09-29 17:43:34 +08:00
parent 024100aa8c
commit f411e17d80
29 changed files with 86 additions and 78 deletions

View File

@@ -1,11 +1,11 @@
package routes
import (
"encoding/json"
"fmt"
"math"
"time"
"github.com/bytedance/sonic"
"github.com/yusing/godoxy/internal/types"
)
@@ -17,7 +17,7 @@ type HealthInfo struct {
}
func (info *HealthInfo) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]any{
return sonic.Marshal(map[string]any{
"status": info.Status.String(),
"latency": info.Latency.Microseconds(),
"uptime": info.Uptime.Milliseconds(),
@@ -32,7 +32,7 @@ func (info *HealthInfo) UnmarshalJSON(data []byte) error {
Uptime int64 `json:"uptime"`
Detail string `json:"detail"`
}
if err := json.Unmarshal(data, &v); err != nil {
if err := sonic.Unmarshal(data, &v); err != nil {
return err
}

View File

@@ -1,8 +1,9 @@
package rules
import (
"encoding/json"
"net/http"
"github.com/bytedance/sonic"
)
type (
@@ -117,7 +118,7 @@ func (rules Rules) MarshalJSON() ([]byte, error) {
for i, rule := range rules {
names[i] = rule.Name
}
return json.Marshal(names)
return sonic.Marshal(names)
}
func (rule *Rule) String() string {