fix: zabbix 请求 localhost 出现 404

This commit is contained in:
Liam Chan 2024-08-23 17:04:39 +08:00
parent 0f4c565250
commit 228ec26904
3 changed files with 6 additions and 6 deletions

View File

@ -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.

View File

@ -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!",
})
}

View File

@ -7,7 +7,7 @@ import (
)
func SetupRoutes(r *gin.Engine) {
r.GET("/ping", handler.Ping)
r.GET("/", handler.Hello)
userGroup := r.Group("/onvif")
{