feat(remote): 显示控制中心和实例版本

This commit is contained in:
yml
2026-11-22 15:26:41 +08:00
parent 0940dd8f85
commit 9ed41d6551
6 changed files with 86 additions and 6 deletions
+10 -1
View File
@@ -26,6 +26,8 @@ type ServerOptions struct {
OperatorToken string
EnrollToken string
EnrollWindow time.Duration
Version string
BuildTime string
}
type Server struct {
@@ -57,6 +59,8 @@ func NewServer(opts ServerOptions) (*Server, error) {
opts.AgentToken = strings.TrimSpace(opts.AgentToken)
opts.OperatorToken = strings.TrimSpace(opts.OperatorToken)
opts.EnrollToken = strings.TrimSpace(opts.EnrollToken)
opts.Version = strings.TrimSpace(opts.Version)
opts.BuildTime = strings.TrimSpace(opts.BuildTime)
if opts.OperatorToken == "" {
return nil, errors.New("OperatorToken 不能为空")
}
@@ -221,6 +225,8 @@ func (s *Server) handleHealth(w http.ResponseWriter, _ *http.Request) {
writeJSON(w, http.StatusOK, map[string]any{
"success": true,
"serverTime": time.Now(),
"version": s.opts.Version,
"buildTime": s.opts.BuildTime,
})
}
@@ -232,7 +238,10 @@ func (s *Server) handleDashboard(w http.ResponseWriter, r *http.Request) {
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
return
}
writeJSON(w, http.StatusOK, s.hub.Dashboard())
dashboard := s.hub.Dashboard()
dashboard.ControlVersion = s.opts.Version
dashboard.ControlBuildTime = s.opts.BuildTime
writeJSON(w, http.StatusOK, dashboard)
}
func (s *Server) handleEvents(w http.ResponseWriter, r *http.Request) {