43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
"os"
|
|
"runtime"
|
|
"time"
|
|
|
|
"bj_power_wms/internal/svc"
|
|
)
|
|
|
|
// processStartTime 进程启动时刻(包加载即服务启动,用于计算运行时长)。
|
|
var processStartTime = time.Now()
|
|
|
|
// SystemInfoHandler GET /api/system/info 只读本机信息面板数据。
|
|
// 含 OS / 主机名 / Go 版本 / 监听端口 / 启动时间 / MES 地址(当前生效值:sys_config 覆盖优先)。
|
|
func SystemInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
host, _ := os.Hostname()
|
|
c := svcCtx.Config
|
|
ok(w, map[string]any{
|
|
"os": runtime.GOOS,
|
|
"hostname": host,
|
|
"goVersion": runtime.Version(),
|
|
"port": c.Port,
|
|
"startTime": processStartTime.Unix(),
|
|
"uptimeSeconds": int64(time.Since(processStartTime).Seconds()),
|
|
"mesAddress": svcCtx.Mes.BaseURL(),
|
|
})
|
|
}
|
|
}
|
|
|
|
// MesPingHandler GET /api/system/mes-ping MES 连通性测试(admin-only,供基础设置页"测试连接")。
|
|
func MesPingHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
if err := svcCtx.Mes.Ping(r.Context()); err != nil {
|
|
fail(w, http.StatusBadGateway, err.Error())
|
|
return
|
|
}
|
|
ok(w, map[string]any{"ok": true, "mesAddress": svcCtx.Mes.BaseURL()})
|
|
}
|
|
}
|