v0.1.27: страница-описание сервиса на корне / (дизайн Nubes) + /static

This commit is contained in:
“Naeel”
2026-08-14 09:05:16 +04:00
parent 5437b9a918
commit af656fe8f5
7 changed files with 357 additions and 4 deletions
+26 -1
View File
@@ -5,13 +5,38 @@ package ui
import (
"embed"
"io/fs"
"net/http"
"strings"
)
//go:embed index.html
//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)))
}