v0.1.27: страница-описание сервиса на корне / (дизайн Nubes) + /static
This commit is contained in:
+26
-1
@@ -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)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user