From d3865bf4d1848dc430a9d6be2de0106114ae92c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9=20=D0=A1=D0=B0?= =?UTF-8?q?=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Sat, 25 Oct 2025 14:23:46 +0300 Subject: [PATCH] try fix err with nil in body --- web/controller/inbound.go | 4 +--- web/service/inbound.go | 13 ++++++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/web/controller/inbound.go b/web/controller/inbound.go index 799830b8..e3477936 100644 --- a/web/controller/inbound.go +++ b/web/controller/inbound.go @@ -13,7 +13,6 @@ import ( "github.com/mhsanaei/3x-ui/v2/web/session" "github.com/gin-gonic/gin" - "github.com/gin-gonic/gin/binding" ) // InboundController handles HTTP requests related to Xray inbounds management. @@ -123,8 +122,7 @@ func (a *InboundController) addInbound(c *gin.Context) { c.Request.Body = io.NopCloser(bytes.NewBuffer(bodyBytes)) inbound := &model.Inbound{} - err := c.ShouldBindWith(inbound, binding.Form) - // err := c.ShouldBind(inbound) + err := c.ShouldBind(inbound) if err != nil { jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err) return diff --git a/web/service/inbound.go b/web/service/inbound.go index ec15ecbb..e319fab3 100644 --- a/web/service/inbound.go +++ b/web/service/inbound.go @@ -2460,7 +2460,18 @@ func (s *InboundService) syncWithSlaves(method string, path string, contentType continue } for key, value := range tmp { - form.Set(key, fmt.Sprintf("%v", value)) + if value == nil { // skip nil fields + continue + } + + // if the field is a slice or a map, marshal it to JSON + switch vv := value.(type) { + case map[string]interface{}, []interface{}: + jsonVal, _ := json.Marshal(vv) + form.Set(key, string(jsonVal)) + default: + form.Set(key, fmt.Sprintf("%v", value)) + } } default: logger.Warningf("Unsupported body type: %T for form encoding on server %s", v, server.Name)