From 228ec269043290c1c8a8db0bfb768dd11bf91ba2 Mon Sep 17 00:00:00 2001 From: imbytecat Date: Fri, 23 Aug 2024 17:04:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20zabbix=20=E8=AF=B7=E6=B1=82=20localhost?= =?UTF-8?q?=20=E5=87=BA=E7=8E=B0=20404?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- integration/zabbixagent/handler.go | 6 +++--- router/handler/{ping.go => hello.go} | 4 ++-- router/router.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) rename router/handler/{ping.go => hello.go} (58%) diff --git a/integration/zabbixagent/handler.go b/integration/zabbixagent/handler.go index 7752017..5decc93 100644 --- a/integration/zabbixagent/handler.go +++ b/integration/zabbixagent/handler.go @@ -35,12 +35,12 @@ func (h *Handler) HTTPClient(ctx context.Context, params map[string]string, _ .. url := params["url"] if !strings.HasPrefix(url, "http") { - url = fmt.Sprintf("http://localhost:%d/%s", config.Config.App.Port, url) + url = fmt.Sprintf("http://127.0.0.1:%d%s", config.Config.App.Port, url) } body := params["body"] - req, err := http.NewRequestWithContext(ctx, method, "https://api.imbytecat.com/ip", strings.NewReader(body)) // TODO: if empty use http.NoBody + req, err := http.NewRequestWithContext(ctx, method, url, strings.NewReader(body)) // TODO: if empty use http.NoBody if err != nil { return nil, errs.Wrapf(err, "failed to create request") } @@ -57,7 +57,7 @@ func (h *Handler) HTTPClient(ctx context.Context, params map[string]string, _ .. return nil, errs.Wrapf(err, "failed to read the response") } - return string(data), nil + return method + url + body + string(data), nil } // NewHandler creates a new handler with initialized clients for system and tcp calls. diff --git a/router/handler/ping.go b/router/handler/hello.go similarity index 58% rename from router/handler/ping.go rename to router/handler/hello.go index 5ec69b5..93e0b92 100644 --- a/router/handler/ping.go +++ b/router/handler/hello.go @@ -4,8 +4,8 @@ import ( "github.com/gin-gonic/gin" ) -func Ping(c *gin.Context) { +func Hello(c *gin.Context) { c.JSON(200, gin.H{ - "message": "pong", + "message": "Hello, World!", }) } diff --git a/router/router.go b/router/router.go index 984171a..9638a9f 100644 --- a/router/router.go +++ b/router/router.go @@ -7,7 +7,7 @@ import ( ) func SetupRoutes(r *gin.Engine) { - r.GET("/ping", handler.Ping) + r.GET("/", handler.Hello) userGroup := r.Group("/onvif") {