From 8fcb8c549a59e3c0e1272d312e14b469cb167170 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: Thu, 23 Oct 2025 16:23:26 +0300 Subject: [PATCH] fix convert model.Inbound to form --- web/service/inbound.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/web/service/inbound.go b/web/service/inbound.go index 798f12ea..867e131e 100644 --- a/web/service/inbound.go +++ b/web/service/inbound.go @@ -2436,6 +2436,7 @@ func (s *InboundService) syncWithSlaves(method string, path string, contentType case "application/x-www-form-urlencoded": form := url.Values{} + switch v := bodyData.(type) { case map[string]string: for key, value := range v { @@ -2445,10 +2446,27 @@ func (s *InboundService) syncWithSlaves(method string, path string, contentType for key, value := range v { form.Set(key, fmt.Sprintf("%v", value)) } + case *model.Inbound: + // Try to marshal the struct to a map through JSON + // This is a universal way to convert struct to form + tmp := make(map[string]interface{}) + data, err := json.Marshal(v) + if err != nil { + logger.Warningf("Failed to marshal struct to JSON for form encoding: %v", err) + continue + } + if err := json.Unmarshal(data, &tmp); err != nil { + logger.Warningf("Failed to unmarshal JSON to map for form encoding: %v", err) + continue + } + for key, value := range tmp { + form.Set(key, fmt.Sprintf("%v", value)) + } default: logger.Warningf("Unsupported body type: %T for form encoding on server %s", v, server.Name) continue } + bodyReader = strings.NewReader(form.Encode()) default: @@ -2481,6 +2499,7 @@ func (s *InboundService) syncWithSlaves(method string, path string, contentType bodyBytes, _ := io.ReadAll(resp.Body) logger.Warningf("Failed to sync with server %s. Status: %s, Body: %s", server.Name, resp.Status, string(bodyBytes)) } + logger.Infof("Synced inbound %v to server %v (%v)", bodyData.(*model.Inbound).Tag, server.Name, resp.Status) } }