[web] 新增超时参数并移除不再使用的超时处理接口

This commit is contained in:
远野千束 2025-01-03 20:57:36 +08:00
parent 682679b63a
commit ed99ffc938
3 changed files with 16 additions and 11 deletions

View File

@ -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()
}

View File

@ -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)
}
// 静态文件

View File

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