mirror of
https://github.com/snowykami/server-status-server.git
synced 2025-09-06 20:16:27 +00:00
✨ first comm
This commit is contained in:
44
api/frontend/handlers.go
Normal file
44
api/frontend/handlers.go
Normal file
@ -0,0 +1,44 @@
|
||||
package frontend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"os"
|
||||
"server-status-be/dao"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func OnGetServerStatus(ctx context.Context, c *app.RequestContext) {
|
||||
ret := make(map[string]interface{})
|
||||
for k, v := range dao.GetAll() {
|
||||
if strings.HasPrefix(k, "report.") {
|
||||
reportName := strings.TrimPrefix(k, "report.")
|
||||
ret[reportName] = v
|
||||
}
|
||||
}
|
||||
c.JSON(200, ret)
|
||||
ctx.Done()
|
||||
}
|
||||
|
||||
func OnGetStaticFile(ctx context.Context, c *app.RequestContext) {
|
||||
file := c.Param("file")
|
||||
fp := "./web/" + file
|
||||
|
||||
if file == "" {
|
||||
fp = "web/index.html"
|
||||
}
|
||||
// 判断文件是否存在
|
||||
if _, err := os.Stat(fp); err != nil {
|
||||
fp += ".html"
|
||||
if _, err := os.Stat(fp); err != nil {
|
||||
c.JSON(404, "File Not Found")
|
||||
return
|
||||
} else {
|
||||
c.File(fp)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
c.File(fp)
|
||||
}
|
||||
ctx.Done()
|
||||
}
|
Reference in New Issue
Block a user