From e14d6baedb539cf26b7e2f028f6691ca26f0bb31 Mon Sep 17 00:00:00 2001 From: yusing Date: Sun, 17 Aug 2025 19:45:08 +0800 Subject: [PATCH] fix(agent): change request binding from query to JSON and update hostport formatting --- internal/api/v1/agent/create.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/api/v1/agent/create.go b/internal/api/v1/agent/create.go index a53c5272..354bf484 100644 --- a/internal/api/v1/agent/create.go +++ b/internal/api/v1/agent/create.go @@ -1,8 +1,9 @@ package agentapi import ( - "fmt" + "net" "net/http" + "strconv" _ "embed" @@ -42,11 +43,11 @@ type NewAgentResponse struct { // @Router /agent/create [post] func Create(c *gin.Context) { var request NewAgentRequest - if err := c.ShouldBindQuery(&request); err != nil { + if err := c.ShouldBindJSON(&request); err != nil { c.JSON(http.StatusBadRequest, apitypes.Error("invalid request", err)) return } - hostport := fmt.Sprintf("%s:%d", request.Host, request.Port) + hostport := net.JoinHostPort(request.Host, strconv.Itoa(request.Port)) if _, ok := agent.GetAgent(hostport); ok { c.JSON(http.StatusConflict, apitypes.Error("agent already exists")) return