package handler import ( "html/template" "net/http" ) // DashboardHandler 是前端页面路由处理器 type DashboardHandler struct { templates *template.Template } func NewDashboardHandler() *DashboardHandler { tmpl := template.Must(template.New("dashboard").Parse(dashboardHTML)) return &DashboardHandler{templates: tmpl} } // RegisterRoutes 注册页面路由 func (h *DashboardHandler) RegisterRoutes(mux *http.ServeMux) { mux.HandleFunc("GET /ops/dashboard", h.Dashboard) mux.HandleFunc("GET /ops/dashboard/logs", h.Dashboard) mux.HandleFunc("GET /ops/dashboard/rules", h.Dashboard) mux.HandleFunc("GET /ops/dashboard/alerts", h.Dashboard) mux.HandleFunc("GET /ops/dashboard/channels", h.Dashboard) } // Dashboard 首页 func (h *DashboardHandler) Dashboard(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html; charset=utf-8") _ = h.templates.ExecuteTemplate(w, "dashboard", nil) } const dashboardHTML = `