mirror of
https://github.com/snowykami/server-status-server.git
synced 2025-06-05 22:55:20 +00:00
✨ [web] 新增超时参数并移除不再使用的超时处理接口
This commit is contained in:
parent
682679b63a
commit
ed99ffc938
@ -3,11 +3,13 @@ package frontend
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"embed"
|
"embed"
|
||||||
|
"server-status-be/dao"
|
||||||
|
"server-status-be/service"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/LiteyukiStudio/go-logger/log"
|
"github.com/LiteyukiStudio/go-logger/log"
|
||||||
"github.com/cloudwego/hertz/pkg/app"
|
"github.com/cloudwego/hertz/pkg/app"
|
||||||
"github.com/gabriel-vasile/mimetype"
|
"github.com/gabriel-vasile/mimetype"
|
||||||
"server-status-be/dao"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed web/*
|
//go:embed web/*
|
||||||
@ -23,6 +25,8 @@ func OnGetServerStatus(ctx context.Context, c *app.RequestContext) {
|
|||||||
ret[reportName] = v
|
ret[reportName] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 加入timeout参数
|
||||||
|
ret["timeout"] = service.Timeout
|
||||||
c.JSON(200, ret)
|
c.JSON(200, ret)
|
||||||
ctx.Done()
|
ctx.Done()
|
||||||
}
|
}
|
||||||
@ -62,9 +66,3 @@ func OnGetStaticFile(ctx context.Context, c *app.RequestContext) {
|
|||||||
log.Info("Get file: ", fp, " with content type: ", contentType)
|
log.Info("Get file: ", fp, " with content type: ", contentType)
|
||||||
c.Data(200, contentType, data)
|
c.Data(200, contentType, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func OnGetTimeout(ctx context.Context, c *app.RequestContext) {
|
|
||||||
log.Info("Timeout")
|
|
||||||
c.JSON(200, "Timeout")
|
|
||||||
ctx.Done()
|
|
||||||
}
|
|
||||||
|
@ -38,7 +38,6 @@ func init() {
|
|||||||
{
|
{
|
||||||
api.GET("/", func(ctx context.Context, c *app.RequestContext) { c.JSON(200, "Hello, api") })
|
api.GET("/", func(ctx context.Context, c *app.RequestContext) { c.JSON(200, "Hello, api") })
|
||||||
api.GET("/status", frontend.OnGetServerStatus)
|
api.GET("/status", frontend.OnGetServerStatus)
|
||||||
api.GET("/timeout", frontend.OnGetTimeout)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 静态文件
|
// 静态文件
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/LiteyukiStudio/go-logger/log"
|
"github.com/LiteyukiStudio/go-logger/log"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Token = "server-status-be-q2dw9adh8"
|
Token = "server-status-be-q2dw9adh8"
|
||||||
|
Timeout = 30
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -15,9 +18,14 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info("Error loading .env file")
|
log.Info("Error loading .env file")
|
||||||
}
|
}
|
||||||
|
|
||||||
token := os.Getenv("TOKEN")
|
token := os.Getenv("TOKEN")
|
||||||
if token != "" {
|
if token != "" {
|
||||||
Token = token
|
Token = token
|
||||||
}
|
}
|
||||||
log.Info("Token: ", Token)
|
log.Info("Token: ", Token)
|
||||||
|
|
||||||
|
if timeout, err := strconv.Atoi(os.Getenv("TIMEOUT")); err == nil {
|
||||||
|
Timeout = timeout
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user