From 5b5d3aac86f4bb17bd610568b3196c1b86cac8ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Sat, 16 Nov 2024 20:58:48 +0800 Subject: [PATCH] Fix render --- cmd/serenity/cmd_export.go | 2 +- server/server_render.go | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/cmd/serenity/cmd_export.go b/cmd/serenity/cmd_export.go index e456cf0..d8fa50b 100644 --- a/cmd/serenity/cmd_export.go +++ b/cmd/serenity/cmd_export.go @@ -104,7 +104,7 @@ func export(profileName string) error { if err != nil { return err } - encoder := json.NewEncoder(os.Stdout) + encoder := json.NewEncoderContext(globalCtx, os.Stdout) encoder.SetIndent("", " ") err = encoder.Encode(boxOptions) if err != nil { diff --git a/server/server_render.go b/server/server_render.go index 9b72a36..6501980 100644 --- a/server/server_render.go +++ b/server/server_render.go @@ -2,7 +2,6 @@ package server import ( "bytes" - "encoding/json" "net/http" "strings" @@ -12,6 +11,7 @@ import ( boxOption "github.com/sagernet/sing-box/option" "github.com/sagernet/sing/common" E "github.com/sagernet/sing/common/exceptions" + "github.com/sagernet/sing/common/json" "github.com/go-chi/chi/v5" "github.com/go-chi/cors" @@ -74,8 +74,7 @@ func (s *Server) render(writer http.ResponseWriter, request *http.Request) { s.accessLog(request, http.StatusNotFound, 0) return } - metadata := M.Detect(request.Header.Get("User-Agent")) - options, err := profile.Render(metadata) + options, err := profile.Render(M.Detect(request.Header.Get("User-Agent"))) if err != nil { s.logger.Error(E.Cause(err, "render options")) render.Status(request, http.StatusInternalServerError) @@ -84,7 +83,7 @@ func (s *Server) render(writer http.ResponseWriter, request *http.Request) { return } var buffer bytes.Buffer - encoder := json.NewEncoder(&buffer) + encoder := json.NewEncoderContext(s.ctx, &buffer) encoder.SetIndent("", " ") err = encoder.Encode(&options) if err != nil {