mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-23 09:18:51 +02:00
fix(agent): change request binding from query to JSON and update hostport formatting
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
package agentapi
|
package agentapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
_ "embed"
|
_ "embed"
|
||||||
|
|
||||||
@@ -42,11 +43,11 @@ type NewAgentResponse struct {
|
|||||||
// @Router /agent/create [post]
|
// @Router /agent/create [post]
|
||||||
func Create(c *gin.Context) {
|
func Create(c *gin.Context) {
|
||||||
var request NewAgentRequest
|
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))
|
c.JSON(http.StatusBadRequest, apitypes.Error("invalid request", err))
|
||||||
return
|
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 {
|
if _, ok := agent.GetAgent(hostport); ok {
|
||||||
c.JSON(http.StatusConflict, apitypes.Error("agent already exists"))
|
c.JSON(http.StatusConflict, apitypes.Error("agent already exists"))
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user