diff --git a/api/frontend/handlers.go b/api/frontend/handlers.go index 55f5bdf..760ceee 100644 --- a/api/frontend/handlers.go +++ b/api/frontend/handlers.go @@ -3,11 +3,13 @@ package frontend import ( "context" "embed" + "server-status-be/dao" + "server-status-be/service" + "strings" + "github.com/LiteyukiStudio/go-logger/log" "github.com/cloudwego/hertz/pkg/app" "github.com/gabriel-vasile/mimetype" - "server-status-be/dao" - "strings" ) //go:embed web/* @@ -23,6 +25,8 @@ func OnGetServerStatus(ctx context.Context, c *app.RequestContext) { ret[reportName] = v } } + // 加入timeout参数 + ret["timeout"] = service.Timeout c.JSON(200, ret) ctx.Done() } @@ -62,9 +66,3 @@ func OnGetStaticFile(ctx context.Context, c *app.RequestContext) { log.Info("Get file: ", fp, " with content type: ", contentType) c.Data(200, contentType, data) } - -func OnGetTimeout(ctx context.Context, c *app.RequestContext) { - log.Info("Timeout") - c.JSON(200, "Timeout") - ctx.Done() -} diff --git a/api/router.go b/api/router.go index 826fdd5..bb347de 100644 --- a/api/router.go +++ b/api/router.go @@ -38,7 +38,6 @@ func init() { { api.GET("/", func(ctx context.Context, c *app.RequestContext) { c.JSON(200, "Hello, api") }) api.GET("/status", frontend.OnGetServerStatus) - api.GET("/timeout", frontend.OnGetTimeout) } // 静态文件 diff --git a/service/config.go b/service/config.go index fef31fa..90da730 100644 --- a/service/config.go +++ b/service/config.go @@ -1,13 +1,16 @@ package service import ( + "os" + "strconv" + "github.com/LiteyukiStudio/go-logger/log" "github.com/joho/godotenv" - "os" ) var ( - Token = "server-status-be-q2dw9adh8" + Token = "server-status-be-q2dw9adh8" + Timeout = 30 ) func init() { @@ -15,9 +18,14 @@ func init() { if err != nil { log.Info("Error loading .env file") } + token := os.Getenv("TOKEN") if token != "" { Token = token } log.Info("Token: ", Token) + + if timeout, err := strconv.Atoi(os.Getenv("TIMEOUT")); err == nil { + Timeout = timeout + } }