try fix err with nil in body

This commit is contained in:
Дмитрий Саенко 2025-10-25 14:23:46 +03:00
parent 0a6e02cf18
commit d3865bf4d1
2 changed files with 13 additions and 4 deletions

View file

@ -13,7 +13,6 @@ import (
"github.com/mhsanaei/3x-ui/v2/web/session" "github.com/mhsanaei/3x-ui/v2/web/session"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
) )
// InboundController handles HTTP requests related to Xray inbounds management. // 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)) c.Request.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
inbound := &model.Inbound{} inbound := &model.Inbound{}
err := c.ShouldBindWith(inbound, binding.Form) err := c.ShouldBind(inbound)
// err := c.ShouldBind(inbound)
if err != nil { if err != nil {
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err) jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return return

View file

@ -2460,7 +2460,18 @@ func (s *InboundService) syncWithSlaves(method string, path string, contentType
continue continue
} }
for key, value := range tmp { 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: default:
logger.Warningf("Unsupported body type: %T for form encoding on server %s", v, server.Name) logger.Warningf("Unsupported body type: %T for form encoding on server %s", v, server.Name)