mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-23 08:48:32 +02:00
feat(json): improve JSON performance with bytedance/sonic
This commit is contained in:
@@ -13,6 +13,7 @@ replace github.com/shirou/gopsutil/v4 => github.com/godoxy-app/gopsutil/v4 v4.0.
|
|||||||
exclude github.com/containerd/nerdctl/mod/tigron v0.0.0
|
exclude github.com/containerd/nerdctl/mod/tigron v0.0.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/bytedance/sonic v1.14.1
|
||||||
github.com/gin-gonic/gin v1.11.0
|
github.com/gin-gonic/gin v1.11.0
|
||||||
github.com/gorilla/websocket v1.5.3
|
github.com/gorilla/websocket v1.5.3
|
||||||
github.com/puzpuzpuz/xsync/v4 v4.2.0
|
github.com/puzpuzpuz/xsync/v4 v4.2.0
|
||||||
@@ -29,7 +30,6 @@ require (
|
|||||||
github.com/PuerkitoBio/goquery v1.10.3 // indirect
|
github.com/PuerkitoBio/goquery v1.10.3 // indirect
|
||||||
github.com/andybalholm/cascadia v1.3.3 // indirect
|
github.com/andybalholm/cascadia v1.3.3 // indirect
|
||||||
github.com/bytedance/gopkg v0.1.3 // indirect
|
github.com/bytedance/gopkg v0.1.3 // indirect
|
||||||
github.com/bytedance/sonic v1.14.1 // indirect
|
|
||||||
github.com/bytedance/sonic/loader v0.3.0 // indirect
|
github.com/bytedance/sonic/loader v0.3.0 // indirect
|
||||||
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
|
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
|
||||||
github.com/cloudwego/base64x v0.1.6 // indirect
|
github.com/cloudwego/base64x v0.1.6 // indirect
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package agentproxy
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
@@ -54,7 +53,7 @@ func proxyConfigFromHeaders(h http.Header) (cfg Config, err error) {
|
|||||||
return cfg, err
|
return cfg, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(cfgJSON, &cfg)
|
err = sonic.Unmarshal(cfgJSON, &cfg)
|
||||||
return cfg, err
|
return cfg, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/bytedance/sonic"
|
||||||
"github.com/yusing/godoxy/internal/types"
|
"github.com/yusing/godoxy/internal/types"
|
||||||
"github.com/yusing/godoxy/internal/watcher/health/monitor"
|
"github.com/yusing/godoxy/internal/watcher/health/monitor"
|
||||||
)
|
)
|
||||||
@@ -78,5 +78,5 @@ func CheckHealth(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(result)
|
sonic.ConfigDefault.NewEncoder(w).Encode(result)
|
||||||
}
|
}
|
||||||
|
|||||||
19
go.mod
19
go.mod
@@ -27,7 +27,6 @@ require (
|
|||||||
github.com/pires/go-proxyproto v0.8.1 // proxy protocol support
|
github.com/pires/go-proxyproto v0.8.1 // proxy protocol support
|
||||||
github.com/puzpuzpuz/xsync/v4 v4.2.0 // lock free map for concurrent operations
|
github.com/puzpuzpuz/xsync/v4 v4.2.0 // lock free map for concurrent operations
|
||||||
github.com/rs/zerolog v1.34.0 // logging
|
github.com/rs/zerolog v1.34.0 // logging
|
||||||
github.com/shirou/gopsutil/v4 v4.25.8 // system info metrics
|
|
||||||
github.com/vincent-petithory/dataurl v1.0.0 // data url for fav icon
|
github.com/vincent-petithory/dataurl v1.0.0 // data url for fav icon
|
||||||
golang.org/x/crypto v0.42.0 // encrypting password with bcrypt
|
golang.org/x/crypto v0.42.0 // encrypting password with bcrypt
|
||||||
golang.org/x/net v0.44.0 // HTTP header utilities
|
golang.org/x/net v0.44.0 // HTTP header utilities
|
||||||
@@ -102,7 +101,6 @@ require (
|
|||||||
github.com/go-jose/go-jose/v4 v4.1.2 // indirect
|
github.com/go-jose/go-jose/v4 v4.1.2 // indirect
|
||||||
github.com/go-logr/logr v1.4.3 // indirect
|
github.com/go-logr/logr v1.4.3 // indirect
|
||||||
github.com/go-logr/stdr v1.2.2 // indirect
|
github.com/go-logr/stdr v1.2.2 // indirect
|
||||||
github.com/go-ole/go-ole v1.3.0 // indirect
|
|
||||||
github.com/go-playground/locales v0.14.1 // indirect
|
github.com/go-playground/locales v0.14.1 // indirect
|
||||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||||
github.com/go-resty/resty/v2 v2.16.5 // indirect
|
github.com/go-resty/resty/v2 v2.16.5 // indirect
|
||||||
@@ -131,7 +129,6 @@ require (
|
|||||||
github.com/linode/linodego v1.59.0 // indirect
|
github.com/linode/linodego v1.59.0 // indirect
|
||||||
github.com/liquidweb/liquidweb-cli v0.7.0 // indirect
|
github.com/liquidweb/liquidweb-cli v0.7.0 // indirect
|
||||||
github.com/liquidweb/liquidweb-go v1.6.4 // indirect
|
github.com/liquidweb/liquidweb-go v1.6.4 // indirect
|
||||||
github.com/lufia/plan9stats v0.0.0-20250827001030-24949be3fa54 // indirect
|
|
||||||
github.com/magefile/mage v1.15.0 // indirect
|
github.com/magefile/mage v1.15.0 // indirect
|
||||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
@@ -160,7 +157,6 @@ require (
|
|||||||
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
|
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||||
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
|
|
||||||
github.com/pquerna/otp v1.5.0 // indirect
|
github.com/pquerna/otp v1.5.0 // indirect
|
||||||
github.com/quic-go/qpack v0.5.1 // indirect
|
github.com/quic-go/qpack v0.5.1 // indirect
|
||||||
github.com/regfish/regfish-dnsapi-go v0.1.1 // indirect
|
github.com/regfish/regfish-dnsapi-go v0.1.1 // indirect
|
||||||
@@ -183,15 +179,12 @@ require (
|
|||||||
github.com/spf13/pflag v1.0.10 // indirect
|
github.com/spf13/pflag v1.0.10 // indirect
|
||||||
github.com/spf13/viper v1.21.0 // indirect
|
github.com/spf13/viper v1.21.0 // indirect
|
||||||
github.com/subosito/gotenv v1.6.0 // indirect
|
github.com/subosito/gotenv v1.6.0 // indirect
|
||||||
github.com/tklauser/go-sysconf v0.3.15 // indirect
|
|
||||||
github.com/tklauser/numcpus v0.10.0 // indirect
|
|
||||||
github.com/transip/gotransip/v6 v6.26.0 // indirect
|
github.com/transip/gotransip/v6 v6.26.0 // indirect
|
||||||
github.com/ultradns/ultradns-go-sdk v1.8.1-20250722213956-faef419 // indirect
|
github.com/ultradns/ultradns-go-sdk v1.8.1-20250722213956-faef419 // indirect
|
||||||
github.com/vinyldns/go-vinyldns v0.9.16 // indirect
|
github.com/vinyldns/go-vinyldns v0.9.16 // indirect
|
||||||
github.com/volcengine/volc-sdk-golang v1.0.221 // indirect
|
github.com/volcengine/volc-sdk-golang v1.0.221 // indirect
|
||||||
github.com/vultr/govultr/v3 v3.24.0 // indirect
|
github.com/vultr/govultr/v3 v3.24.0 // indirect
|
||||||
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
|
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
|
||||||
github.com/yusufpapurcu/wmi v1.2.4 // indirect
|
|
||||||
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
|
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
|
||||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0 // indirect
|
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0 // indirect
|
||||||
go.opentelemetry.io/otel v1.38.0 // indirect
|
go.opentelemetry.io/otel v1.38.0 // indirect
|
||||||
@@ -214,11 +207,15 @@ require (
|
|||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/bytedance/sonic v1.14.1
|
||||||
|
github.com/shirou/gopsutil/v4 v4.25.8
|
||||||
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/akamai/AkamaiOPEN-edgegrid-golang/v11 v11.1.0 // indirect
|
github.com/akamai/AkamaiOPEN-edgegrid-golang/v11 v11.1.0 // indirect
|
||||||
github.com/aziontech/azionapi-go-sdk v0.143.0 // indirect
|
github.com/aziontech/azionapi-go-sdk v0.143.0 // indirect
|
||||||
github.com/bytedance/gopkg v0.1.3 // indirect
|
github.com/bytedance/gopkg v0.1.3 // indirect
|
||||||
github.com/bytedance/sonic v1.14.1 // indirect
|
|
||||||
github.com/bytedance/sonic/loader v0.3.0 // indirect
|
github.com/bytedance/sonic/loader v0.3.0 // indirect
|
||||||
github.com/cloudwego/base64x v0.1.6 // indirect
|
github.com/cloudwego/base64x v0.1.6 // indirect
|
||||||
github.com/containerd/errdefs v1.0.0 // indirect
|
github.com/containerd/errdefs v1.0.0 // indirect
|
||||||
@@ -227,10 +224,12 @@ require (
|
|||||||
github.com/dnsimple/dnsimple-go/v4 v4.0.0 // indirect
|
github.com/dnsimple/dnsimple-go/v4 v4.0.0 // indirect
|
||||||
github.com/fatih/color v1.18.0 // indirect
|
github.com/fatih/color v1.18.0 // indirect
|
||||||
github.com/gin-contrib/sse v1.1.0 // indirect
|
github.com/gin-contrib/sse v1.1.0 // indirect
|
||||||
|
github.com/go-ole/go-ole v1.3.0 // indirect
|
||||||
github.com/go-ozzo/ozzo-validation/v4 v4.3.0 // indirect
|
github.com/go-ozzo/ozzo-validation/v4 v4.3.0 // indirect
|
||||||
github.com/goccy/go-json v0.10.5 // indirect
|
github.com/goccy/go-json v0.10.5 // indirect
|
||||||
github.com/klauspost/compress v1.18.0 // indirect
|
github.com/klauspost/compress v1.18.0 // indirect
|
||||||
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
|
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
|
||||||
|
github.com/lufia/plan9stats v0.0.0-20250827001030-24949be3fa54 // indirect
|
||||||
github.com/moby/sys/atomicwriter v0.1.0 // indirect
|
github.com/moby/sys/atomicwriter v0.1.0 // indirect
|
||||||
github.com/moby/term v0.5.2 // indirect
|
github.com/moby/term v0.5.2 // indirect
|
||||||
github.com/morikuni/aec v1.0.0 // indirect
|
github.com/morikuni/aec v1.0.0 // indirect
|
||||||
@@ -240,10 +239,14 @@ require (
|
|||||||
github.com/onsi/ginkgo/v2 v2.25.1 // indirect
|
github.com/onsi/ginkgo/v2 v2.25.1 // indirect
|
||||||
github.com/onsi/gomega v1.38.1 // indirect
|
github.com/onsi/gomega v1.38.1 // indirect
|
||||||
github.com/pierrec/lz4/v4 v4.1.21 // indirect
|
github.com/pierrec/lz4/v4 v4.1.21 // indirect
|
||||||
|
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
|
||||||
github.com/selectel/go-selvpcclient/v4 v4.1.0 // indirect
|
github.com/selectel/go-selvpcclient/v4 v4.1.0 // indirect
|
||||||
github.com/stretchr/objx v0.5.2 // indirect
|
github.com/stretchr/objx v0.5.2 // indirect
|
||||||
|
github.com/tklauser/go-sysconf v0.3.15 // indirect
|
||||||
|
github.com/tklauser/numcpus v0.10.0 // indirect
|
||||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||||
github.com/ugorji/go/codec v1.3.0 // indirect
|
github.com/ugorji/go/codec v1.3.0 // indirect
|
||||||
|
github.com/yusufpapurcu/wmi v1.2.4 // indirect
|
||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.37.0 // indirect
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.37.0 // indirect
|
||||||
go.yaml.in/yaml/v3 v3.0.4 // indirect
|
go.yaml.in/yaml/v3 v3.0.4 // indirect
|
||||||
golang.org/x/arch v0.21.0 // indirect
|
golang.org/x/arch v0.21.0 // indirect
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/bytedance/sonic"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/yusing/godoxy/agent/pkg/agent"
|
"github.com/yusing/godoxy/agent/pkg/agent"
|
||||||
@@ -256,7 +257,7 @@ func marshalSystemInfo(ws *websocket.Manager, agentName string, systemInfo any)
|
|||||||
}
|
}
|
||||||
|
|
||||||
buf := bytes.NewBuffer(bytesBuf)
|
buf := bytes.NewBuffer(bytesBuf)
|
||||||
err := json.NewEncoder(buf).Encode(map[string]any{
|
err := sonic.ConfigDefault.NewEncoder(buf).Encode(map[string]any{
|
||||||
agentName: systemInfo,
|
agentName: systemInfo,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package auth
|
package auth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/bytedance/sonic"
|
||||||
"github.com/golang-jwt/jwt/v5"
|
"github.com/golang-jwt/jwt/v5"
|
||||||
"github.com/yusing/godoxy/internal/common"
|
"github.com/yusing/godoxy/internal/common"
|
||||||
gperr "github.com/yusing/goutils/errs"
|
gperr "github.com/yusing/goutils/errs"
|
||||||
@@ -109,7 +109,7 @@ type UserPassAuthCallbackRequest struct {
|
|||||||
|
|
||||||
func (auth *UserPassAuth) PostAuthCallbackHandler(w http.ResponseWriter, r *http.Request) {
|
func (auth *UserPassAuth) PostAuthCallbackHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
var creds UserPassAuthCallbackRequest
|
var creds UserPassAuthCallbackRequest
|
||||||
err := json.NewDecoder(r.Body).Decode(&creds)
|
err := sonic.ConfigDefault.NewDecoder(r.Body).Decode(&creds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "invalid request", http.StatusBadRequest)
|
http.Error(w, "invalid request", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ package homepage
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/bytedance/sonic"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/yusing/godoxy/internal/common"
|
"github.com/yusing/godoxy/internal/common"
|
||||||
"github.com/yusing/godoxy/internal/jsonstore"
|
"github.com/yusing/godoxy/internal/jsonstore"
|
||||||
@@ -123,8 +123,8 @@ func (e *cacheEntry) UnmarshalJSON(data []byte) error {
|
|||||||
LastAccess time.Time `json:"last_access"`
|
LastAccess time.Time `json:"last_access"`
|
||||||
}
|
}
|
||||||
// check if data is json
|
// check if data is json
|
||||||
if json.Valid(data) {
|
if sonic.Valid(data) {
|
||||||
err := json.Unmarshal(data, &tmp)
|
err := sonic.Unmarshal(data, &tmp)
|
||||||
// return only if unmarshal is successful
|
// return only if unmarshal is successful
|
||||||
// otherwise fallback to base64
|
// otherwise fallback to base64
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ package qbittorrent
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
|
"github.com/bytedance/sonic"
|
||||||
"github.com/yusing/godoxy/internal/homepage/widgets"
|
"github.com/yusing/godoxy/internal/homepage/widgets"
|
||||||
gperr "github.com/yusing/goutils/errs"
|
gperr "github.com/yusing/goutils/errs"
|
||||||
)
|
)
|
||||||
@@ -59,7 +59,7 @@ func jsonRequest[T any](ctx context.Context, client *Client, endpoint string, qu
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
err = json.NewDecoder(resp.Body).Decode(&result)
|
err = sonic.ConfigDefault.NewDecoder(resp.Body).Decode(&result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ package qbittorrent
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/bytedance/sonic"
|
||||||
)
|
)
|
||||||
|
|
||||||
const endpointLogs = "/api/v2/log/main"
|
const endpointLogs = "/api/v2/log/main"
|
||||||
@@ -44,7 +45,7 @@ func (l *LogEntry) Level() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *LogEntry) MarshalJSON() ([]byte, error) {
|
func (l *LogEntry) MarshalJSON() ([]byte, error) {
|
||||||
return json.Marshal(map[string]any{
|
return sonic.Marshal(map[string]any{
|
||||||
"id": l.ID,
|
"id": l.ID,
|
||||||
"timestamp": l.Timestamp,
|
"timestamp": l.Timestamp,
|
||||||
"level": l.Level(),
|
"level": l.Level(),
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package homepage
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -11,6 +10,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/bytedance/sonic"
|
||||||
"github.com/lithammer/fuzzysearch/fuzzy"
|
"github.com/lithammer/fuzzysearch/fuzzy"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/yusing/godoxy/internal/common"
|
"github.com/yusing/godoxy/internal/common"
|
||||||
@@ -310,7 +310,7 @@ func UpdateWalkxCodeIcons() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data := make(map[string][]string)
|
data := make(map[string][]string)
|
||||||
err = json.Unmarshal(body, &data)
|
err = sonic.Unmarshal(body, &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -381,7 +381,7 @@ func UpdateSelfhstIcons() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data := make([]SelfhStIcon, 0)
|
data := make([]SelfhStIcon, 0)
|
||||||
err = json.Unmarshal(body, &data) //nolint:musttag
|
err = sonic.Unmarshal(body, &data) //nolint:musttag
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package idlewatcher
|
package idlewatcher
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"iter"
|
"iter"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/bytedance/sonic"
|
||||||
strutils "github.com/yusing/goutils/strings"
|
strutils "github.com/yusing/goutils/strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ type watcherDebug struct {
|
|||||||
|
|
||||||
func (w watcherDebug) MarshalJSON() ([]byte, error) {
|
func (w watcherDebug) MarshalJSON() ([]byte, error) {
|
||||||
state := w.state.Load()
|
state := w.state.Load()
|
||||||
return json.Marshal(map[string]any{
|
return sonic.Marshal(map[string]any{
|
||||||
"name": w.Name(),
|
"name": w.Name(),
|
||||||
"state": map[string]string{
|
"state": map[string]string{
|
||||||
"status": string(state.status),
|
"status": string(state.status),
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/bytedance/sonic"
|
||||||
"github.com/puzpuzpuz/xsync/v4"
|
"github.com/puzpuzpuz/xsync/v4"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/yusing/godoxy/internal/common"
|
"github.com/yusing/godoxy/internal/common"
|
||||||
@@ -66,7 +67,7 @@ func loadNS[T store](ns namespace) T {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
if err := json.NewDecoder(file).Decode(&store); err != nil {
|
if err := sonic.ConfigDefault.NewDecoder(file).Decode(&store); err != nil {
|
||||||
log.Err(err).
|
log.Err(err).
|
||||||
Str("path", path).
|
Str("path", path).
|
||||||
Msg("failed to load store")
|
Msg("failed to load store")
|
||||||
@@ -113,12 +114,12 @@ func (s *MapStore[VT]) Initialize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s MapStore[VT]) MarshalJSON() ([]byte, error) {
|
func (s MapStore[VT]) MarshalJSON() ([]byte, error) {
|
||||||
return json.Marshal(maps.Collect(s.Range))
|
return sonic.Marshal(maps.Collect(s.Range))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MapStore[VT]) UnmarshalJSON(data []byte) error {
|
func (s *MapStore[VT]) UnmarshalJSON(data []byte) error {
|
||||||
tmp := make(map[string]VT)
|
tmp := make(map[string]VT)
|
||||||
if err := json.Unmarshal(data, &tmp); err != nil {
|
if err := sonic.Unmarshal(data, &tmp); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s.Map = xsync.NewMap[string, VT](xsync.WithPresize(len(tmp)))
|
s.Map = xsync.NewMap[string, VT](xsync.WithPresize(len(tmp)))
|
||||||
@@ -134,10 +135,10 @@ func (obj *ObjectStore[Ptr]) Initialize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (obj ObjectStore[Ptr]) MarshalJSON() ([]byte, error) {
|
func (obj ObjectStore[Ptr]) MarshalJSON() ([]byte, error) {
|
||||||
return json.Marshal(obj.ptr)
|
return sonic.Marshal(obj.ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (obj *ObjectStore[Ptr]) UnmarshalJSON(data []byte) error {
|
func (obj *ObjectStore[Ptr]) UnmarshalJSON(data []byte) error {
|
||||||
obj.Initialize()
|
obj.Initialize()
|
||||||
return json.Unmarshal(data, obj.ptr)
|
return sonic.Unmarshal(data, obj.ptr)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
package period
|
package period
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/bytedance/sonic"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Entries[T any] struct {
|
type Entries[T any] struct {
|
||||||
@@ -64,7 +65,7 @@ func (e *Entries[T]) Get() []T {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *Entries[T]) MarshalJSON() ([]byte, error) {
|
func (e *Entries[T]) MarshalJSON() ([]byte, error) {
|
||||||
return json.Marshal(map[string]any{
|
return sonic.Marshal(map[string]any{
|
||||||
"entries": e.Get(),
|
"entries": e.Get(),
|
||||||
"interval": e.interval,
|
"interval": e.interval,
|
||||||
})
|
})
|
||||||
@@ -75,7 +76,7 @@ func (e *Entries[T]) UnmarshalJSON(data []byte) error {
|
|||||||
Entries []T `json:"entries"`
|
Entries []T `json:"entries"`
|
||||||
Interval time.Duration `json:"interval"`
|
Interval time.Duration `json:"interval"`
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal(data, &v); err != nil {
|
if err := sonic.Unmarshal(data, &v); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(v.Entries) == 0 {
|
if len(v.Entries) == 0 {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/bytedance/sonic"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/yusing/godoxy/internal/utils/atomic"
|
"github.com/yusing/godoxy/internal/utils/atomic"
|
||||||
gperr "github.com/yusing/goutils/errs"
|
gperr "github.com/yusing/goutils/errs"
|
||||||
@@ -73,7 +74,7 @@ func (p *Poller[T, AggregateT]) load() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal(entries, &p.period); err != nil {
|
if err := sonic.Unmarshal(entries, &p.period); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Validate and fix intervals after loading to ensure data integrity.
|
// Validate and fix intervals after loading to ensure data integrity.
|
||||||
@@ -83,7 +84,7 @@ func (p *Poller[T, AggregateT]) load() error {
|
|||||||
|
|
||||||
func (p *Poller[T, AggregateT]) save() error {
|
func (p *Poller[T, AggregateT]) save() error {
|
||||||
initDataDirOnce.Do(initDataDir)
|
initDataDirOnce.Do(initDataDir)
|
||||||
entries, err := json.Marshal(p.period)
|
entries, err := sonic.Marshal(p.period)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ package uptime
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"slices"
|
"slices"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/bytedance/sonic"
|
||||||
"github.com/lithammer/fuzzysearch/fuzzy"
|
"github.com/lithammer/fuzzysearch/fuzzy"
|
||||||
config "github.com/yusing/godoxy/internal/config/types"
|
config "github.com/yusing/godoxy/internal/config/types"
|
||||||
"github.com/yusing/godoxy/internal/metrics/period"
|
"github.com/yusing/godoxy/internal/metrics/period"
|
||||||
@@ -50,7 +50,7 @@ func getStatuses(ctx context.Context, _ *StatusByAlias) (*StatusByAlias, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Status) MarshalJSON() ([]byte, error) {
|
func (s *Status) MarshalJSON() ([]byte, error) {
|
||||||
return json.Marshal(map[string]any{
|
return sonic.Marshal(map[string]any{
|
||||||
"status": s.Status.String(),
|
"status": s.Status.String(),
|
||||||
"latency": s.Latency,
|
"latency": s.Latency,
|
||||||
"timestamp": s.Timestamp,
|
"timestamp": s.Timestamp,
|
||||||
@@ -163,5 +163,5 @@ func (rs RouteStatuses) aggregate(limit int, offset int) Aggregated {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (result Aggregated) MarshalJSON() ([]byte, error) {
|
func (result Aggregated) MarshalJSON() ([]byte, error) {
|
||||||
return json.Marshal([]RouteAggregate(result))
|
return sonic.Marshal([]RouteAggregate(result))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package captcha
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -12,6 +11,7 @@ import (
|
|||||||
|
|
||||||
_ "embed"
|
_ "embed"
|
||||||
|
|
||||||
|
"github.com/bytedance/sonic"
|
||||||
gperr "github.com/yusing/goutils/errs"
|
gperr "github.com/yusing/goutils/errs"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ func (p *HcaptchaProvider) Verify(r *http.Request) error {
|
|||||||
Success bool `json:"success"`
|
Success bool `json:"success"`
|
||||||
Error []string `json:"error-codes"`
|
Error []string `json:"error-codes"`
|
||||||
}
|
}
|
||||||
if err := json.NewDecoder(resp.Body).Decode(&respData); err != nil {
|
if err := sonic.ConfigDefault.NewDecoder(resp.Body).Decode(&respData); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package middleware
|
package middleware
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"maps"
|
"maps"
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/bytedance/sonic"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/yusing/godoxy/internal/serialization"
|
"github.com/yusing/godoxy/internal/serialization"
|
||||||
@@ -152,7 +152,7 @@ func (m *Middleware) MarshalJSON() ([]byte, error) {
|
|||||||
commonOptions
|
commonOptions
|
||||||
any
|
any
|
||||||
}
|
}
|
||||||
return json.MarshalIndent(map[string]any{
|
return sonic.MarshalIndent(map[string]any{
|
||||||
"name": m.name,
|
"name": m.name,
|
||||||
"options": allOptions{
|
"options": allOptions{
|
||||||
commonOptions: m.commonOptions,
|
commonOptions: m.commonOptions,
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ package middleware
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"encoding/json"
|
|
||||||
"io"
|
"io"
|
||||||
"maps"
|
"maps"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
|
||||||
|
"github.com/bytedance/sonic"
|
||||||
"github.com/yusing/godoxy/internal/common"
|
"github.com/yusing/godoxy/internal/common"
|
||||||
nettypes "github.com/yusing/godoxy/internal/net/types"
|
nettypes "github.com/yusing/godoxy/internal/net/types"
|
||||||
gperr "github.com/yusing/goutils/errs"
|
gperr "github.com/yusing/goutils/errs"
|
||||||
@@ -24,7 +24,7 @@ func init() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
tmp := map[string]string{}
|
tmp := map[string]string{}
|
||||||
err := json.Unmarshal(testHeadersRaw, &tmp)
|
err := sonic.Unmarshal(testHeadersRaw, &tmp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package notif
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/bytedance/sonic"
|
||||||
gperr "github.com/yusing/goutils/errs"
|
gperr "github.com/yusing/goutils/errs"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ func (f FieldsBody) Format(format *LogFormat) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
return msg.Bytes(), nil
|
return msg.Bytes(), nil
|
||||||
case LogFormatRawJSON:
|
case LogFormatRawJSON:
|
||||||
return json.Marshal(f)
|
return sonic.Marshal(f)
|
||||||
}
|
}
|
||||||
return f.Format(LogFormatMarkdown)
|
return f.Format(LogFormatMarkdown)
|
||||||
}
|
}
|
||||||
@@ -101,7 +101,7 @@ func (l ListBody) Format(format *LogFormat) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
return msg.Bytes(), nil
|
return msg.Bytes(), nil
|
||||||
case LogFormatRawJSON:
|
case LogFormatRawJSON:
|
||||||
return json.Marshal(l)
|
return sonic.Marshal(l)
|
||||||
}
|
}
|
||||||
return l.Format(LogFormatMarkdown)
|
return l.Format(LogFormatMarkdown)
|
||||||
}
|
}
|
||||||
@@ -111,7 +111,7 @@ func (m MessageBody) Format(format *LogFormat) ([]byte, error) {
|
|||||||
case LogFormatPlain, LogFormatMarkdown:
|
case LogFormatPlain, LogFormatMarkdown:
|
||||||
return []byte(m), nil
|
return []byte(m), nil
|
||||||
case LogFormatRawJSON:
|
case LogFormatRawJSON:
|
||||||
return json.Marshal(m)
|
return sonic.Marshal(m)
|
||||||
}
|
}
|
||||||
return m.Format(LogFormatMarkdown)
|
return m.Format(LogFormatMarkdown)
|
||||||
}
|
}
|
||||||
@@ -119,7 +119,7 @@ func (m MessageBody) Format(format *LogFormat) ([]byte, error) {
|
|||||||
func (e ErrorBody) Format(format *LogFormat) ([]byte, error) {
|
func (e ErrorBody) Format(format *LogFormat) ([]byte, error) {
|
||||||
switch format {
|
switch format {
|
||||||
case LogFormatRawJSON:
|
case LogFormatRawJSON:
|
||||||
return json.Marshal(e.Error)
|
return sonic.Marshal(e.Error)
|
||||||
case LogFormatPlain:
|
case LogFormatPlain:
|
||||||
return gperr.Plain(e.Error), nil
|
return gperr.Plain(e.Error), nil
|
||||||
case LogFormatMarkdown:
|
case LogFormatMarkdown:
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package notif
|
package notif
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
|
"github.com/bytedance/sonic"
|
||||||
"github.com/gotify/server/v2/model"
|
"github.com/gotify/server/v2/model"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
)
|
)
|
||||||
@@ -54,7 +54,7 @@ func (client *GotifyClient) MarshalMessage(logMsg *LogMessage) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := json.Marshal(msg)
|
data, err := sonic.Marshal(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,7 @@ func (client *GotifyClient) MarshalMessage(logMsg *LogMessage) ([]byte, error) {
|
|||||||
// fmtError implements Provider.
|
// fmtError implements Provider.
|
||||||
func (client *GotifyClient) fmtError(respBody io.Reader) error {
|
func (client *GotifyClient) fmtError(respBody io.Reader) error {
|
||||||
var errm model.Error
|
var errm model.Error
|
||||||
err := json.NewDecoder(respBody).Decode(&errm)
|
err := sonic.ConfigDefault.NewDecoder(respBody).Decode(&errm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to decode err response: %w", err)
|
return fmt.Errorf("failed to decode err response: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ package notif
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"encoding/json"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/bytedance/sonic"
|
||||||
gperr "github.com/yusing/goutils/errs"
|
gperr "github.com/yusing/goutils/errs"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ func (webhook *Webhook) fmtError(respBody io.Reader) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (webhook *Webhook) MarshalMessage(logMsg *LogMessage) ([]byte, error) {
|
func (webhook *Webhook) MarshalMessage(logMsg *LogMessage) ([]byte, error) {
|
||||||
title, err := json.Marshal(logMsg.Title)
|
title, err := sonic.Marshal(logMsg.Title)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -118,7 +118,7 @@ func (webhook *Webhook) MarshalMessage(logMsg *LogMessage) ([]byte, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if webhook.MIMEType == MimeTypeJSON {
|
if webhook.MIMEType == MimeTypeJSON {
|
||||||
message, err = json.Marshal(string(message))
|
message, err = sonic.Marshal(string(message))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -147,5 +147,5 @@ func validateJSONPayload(payload string) bool {
|
|||||||
"$color", "",
|
"$color", "",
|
||||||
)
|
)
|
||||||
payload = replacer.Replace(payload)
|
payload = replacer.Replace(payload)
|
||||||
return json.Valid([]byte(payload))
|
return sonic.Valid([]byte(payload))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package proxmox
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/bytedance/sonic"
|
||||||
"github.com/luthermonson/go-proxmox"
|
"github.com/luthermonson/go-proxmox"
|
||||||
"github.com/yusing/godoxy/internal/utils/pool"
|
"github.com/yusing/godoxy/internal/utils/pool"
|
||||||
)
|
)
|
||||||
@@ -47,7 +47,7 @@ func (c *Client) Name() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) MarshalJSON() ([]byte, error) {
|
func (c *Client) MarshalJSON() ([]byte, error) {
|
||||||
return json.Marshal(map[string]any{
|
return sonic.Marshal(map[string]any{
|
||||||
"version": c.Version,
|
"version": c.Version,
|
||||||
"cluster": map[string]any{
|
"cluster": map[string]any{
|
||||||
"name": c.Cluster.Name,
|
"name": c.Cluster.Name,
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ package proxmox
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/bytedance/sonic"
|
||||||
"github.com/luthermonson/go-proxmox"
|
"github.com/luthermonson/go-proxmox"
|
||||||
"github.com/yusing/godoxy/internal/utils/pool"
|
"github.com/yusing/godoxy/internal/utils/pool"
|
||||||
)
|
)
|
||||||
@@ -40,7 +40,7 @@ func (n *Node) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) MarshalJSON() ([]byte, error) {
|
func (n *Node) MarshalJSON() ([]byte, error) {
|
||||||
return json.Marshal(map[string]any{
|
return sonic.Marshal(map[string]any{
|
||||||
"name": n.name,
|
"name": n.name,
|
||||||
"id": n.id,
|
"id": n.id,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package routes
|
package routes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/bytedance/sonic"
|
||||||
"github.com/yusing/godoxy/internal/types"
|
"github.com/yusing/godoxy/internal/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ type HealthInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (info *HealthInfo) MarshalJSON() ([]byte, error) {
|
func (info *HealthInfo) MarshalJSON() ([]byte, error) {
|
||||||
return json.Marshal(map[string]any{
|
return sonic.Marshal(map[string]any{
|
||||||
"status": info.Status.String(),
|
"status": info.Status.String(),
|
||||||
"latency": info.Latency.Microseconds(),
|
"latency": info.Latency.Microseconds(),
|
||||||
"uptime": info.Uptime.Milliseconds(),
|
"uptime": info.Uptime.Milliseconds(),
|
||||||
@@ -32,7 +32,7 @@ func (info *HealthInfo) UnmarshalJSON(data []byte) error {
|
|||||||
Uptime int64 `json:"uptime"`
|
Uptime int64 `json:"uptime"`
|
||||||
Detail string `json:"detail"`
|
Detail string `json:"detail"`
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal(data, &v); err != nil {
|
if err := sonic.Unmarshal(data, &v); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
package rules
|
package rules
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/bytedance/sonic"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@@ -117,7 +118,7 @@ func (rules Rules) MarshalJSON() ([]byte, error) {
|
|||||||
for i, rule := range rules {
|
for i, rule := range rules {
|
||||||
names[i] = rule.Name
|
names[i] = rule.Name
|
||||||
}
|
}
|
||||||
return json.Marshal(names)
|
return sonic.Marshal(names)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rule *Rule) String() string {
|
func (rule *Rule) String() string {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package serialization
|
package serialization
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
@@ -10,6 +9,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/bytedance/sonic"
|
||||||
"github.com/go-playground/validator/v10"
|
"github.com/go-playground/validator/v10"
|
||||||
"github.com/goccy/go-yaml"
|
"github.com/goccy/go-yaml"
|
||||||
"github.com/puzpuzpuz/xsync/v4"
|
"github.com/puzpuzpuz/xsync/v4"
|
||||||
@@ -594,7 +594,7 @@ func loadSerialized[T any](path string, dst *T, deserialize func(data []byte, ds
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SaveJSON[T any](path string, src *T, perm os.FileMode) error {
|
func SaveJSON[T any](path string, src *T, perm os.FileMode) error {
|
||||||
data, err := json.Marshal(src)
|
data, err := sonic.Marshal(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -602,7 +602,7 @@ func SaveJSON[T any](path string, src *T, perm os.FileMode) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func LoadJSONIfExist[T any](path string, dst *T) error {
|
func LoadJSONIfExist[T any](path string, dst *T) error {
|
||||||
err := loadSerialized(path, dst, json.Unmarshal)
|
err := loadSerialized(path, dst, sonic.Unmarshal)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"github.com/bytedance/sonic"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/yusing/ds/ordered"
|
"github.com/yusing/ds/ordered"
|
||||||
"github.com/yusing/godoxy/agent/pkg/agent"
|
"github.com/yusing/godoxy/agent/pkg/agent"
|
||||||
@@ -79,5 +78,5 @@ func (e *ContainerError) Unwrap() error {
|
|||||||
|
|
||||||
func (e *ContainerError) MarshalJSON() ([]byte, error) {
|
func (e *ContainerError) MarshalJSON() ([]byte, error) {
|
||||||
err := e.errs.Error().(interface{ Plain() []byte })
|
err := e.errs.Error().(interface{ Plain() []byte })
|
||||||
return json.Marshal(string(err.Plain()))
|
return sonic.Marshal(string(err.Plain()))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/bytedance/sonic"
|
||||||
strutils "github.com/yusing/goutils/strings"
|
strutils "github.com/yusing/goutils/strings"
|
||||||
"github.com/yusing/goutils/task"
|
"github.com/yusing/goutils/task"
|
||||||
)
|
)
|
||||||
@@ -145,7 +146,7 @@ func (s HealthStatus) MarshalJSON() ([]byte, error) {
|
|||||||
|
|
||||||
func (s *HealthStatus) UnmarshalJSON(data []byte) error {
|
func (s *HealthStatus) UnmarshalJSON(data []byte) error {
|
||||||
var v any
|
var v any
|
||||||
if err := json.Unmarshal(data, &v); err != nil {
|
if err := sonic.Unmarshal(data, &v); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
switch v := v.(type) {
|
switch v := v.(type) {
|
||||||
@@ -169,7 +170,7 @@ func (jsonRepr *HealthJSONRepr) MarshalJSON() ([]byte, error) {
|
|||||||
if url == "http://:0" {
|
if url == "http://:0" {
|
||||||
url = ""
|
url = ""
|
||||||
}
|
}
|
||||||
return json.Marshal(HealthJSON{
|
return sonic.Marshal(HealthJSON{
|
||||||
Name: jsonRepr.Name,
|
Name: jsonRepr.Name,
|
||||||
Config: jsonRepr.Config,
|
Config: jsonRepr.Config,
|
||||||
Started: jsonRepr.Started.Unix(),
|
Started: jsonRepr.Started.Unix(),
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package monitor
|
package monitor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/bytedance/sonic"
|
||||||
agentPkg "github.com/yusing/godoxy/agent/pkg/agent"
|
agentPkg "github.com/yusing/godoxy/agent/pkg/agent"
|
||||||
"github.com/yusing/godoxy/internal/types"
|
"github.com/yusing/godoxy/internal/types"
|
||||||
)
|
)
|
||||||
@@ -70,7 +70,7 @@ func (mon *AgentProxiedMonitor) CheckHealth() (result types.HealthCheckResult, e
|
|||||||
endTime := time.Now()
|
endTime := time.Now()
|
||||||
switch status {
|
switch status {
|
||||||
case http.StatusOK:
|
case http.StatusOK:
|
||||||
err = json.Unmarshal(data, &result)
|
err = sonic.Unmarshal(data, &result)
|
||||||
default:
|
default:
|
||||||
err = errors.New(string(data))
|
err = errors.New(string(data))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user