// app/ui/embed.go // Встраивание и раздача UI (SPA) для shared-sqs console // Created: 2026-04-10 package ui import ( "embed" "io/fs" "net/http" "strings" ) //go:embed index.html info.html admin.html examples.html static var content embed.FS // Handler — возвращает http.Handler, раздающий встроенный index.html func Handler() http.Handler { return http.FileServer(http.FS(content)) } // InfoHandler — публичная страница-описание сервиса (GET /) с подстановкой версии func InfoHandler(version string) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { body, err := content.ReadFile("info.html") if err != nil { http.Error(w, "info page unavailable", http.StatusInternalServerError) return } html := strings.ReplaceAll(string(body), "{{VERSION}}", version) w.Header().Set("Content-Type", "text/html; charset=utf-8") _, _ = w.Write([]byte(html)) }) } // AdminHandler — админская консоль (GET /admin) с подстановкой версии func AdminHandler(version string) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { body, err := content.ReadFile("admin.html") if err != nil { http.Error(w, "admin page unavailable", http.StatusInternalServerError) return } html := strings.ReplaceAll(string(body), "{{VERSION}}", version) w.Header().Set("Content-Type", "text/html; charset=utf-8") _, _ = w.Write([]byte(html)) }) } // ExamplesHandler — страница примеров команд (GET /examples) с подстановкой версии func ExamplesHandler(version string) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { body, err := content.ReadFile("examples.html") if err != nil { http.Error(w, "examples page unavailable", http.StatusInternalServerError) return } html := strings.ReplaceAll(string(body), "{{VERSION}}", version) w.Header().Set("Content-Type", "text/html; charset=utf-8") _, _ = w.Write([]byte(html)) }) } // StaticHandler — раздаёт /static/* (логотип, favicon) для публичных страниц func StaticHandler() http.Handler { sub, err := fs.Sub(content, "static") if err != nil { panic(err) } return http.StripPrefix("/static/", http.FileServer(http.FS(sub))) }