Files
SQS-service/app/ui/embed.go
T

43 lines
1.3 KiB
Go

// 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 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))
})
}
// 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)))
}