Files
IoT/internal/service/api/landing_embed.go
T

41 lines
1.2 KiB
Go

// landing_embed.go — встраивает лендинг-инструкцию и статику (лого, favicon).
package api
import (
"embed"
"io/fs"
"net/http"
"strings"
)
// landingHTML — лендинг "/" с инструкцией (дизайн shared-sqs).
//
//go:embed ui/landing.html
var landingHTML []byte
// staticFS — логотип и favicon (дизайн Nubes, как на shared-sqs).
//
//go:embed ui/static
var staticFS embed.FS
// versionPlaceholder — заменяется на версию при отдаче страницы.
const versionPlaceholder = "{{VERSION}}"
// ServeLanding отдаёт лендинг "/" с подставленной версией.
func ServeLanding(w http.ResponseWriter, r *http.Request, version string) {
body := strings.ReplaceAll(string(landingHTML), versionPlaceholder, version)
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.Header().Set("Cache-Control", "no-cache, must-revalidate")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(body))
}
// StaticHandler раздаёт /static/* (logo.svg, favicon.svg) из embed.
func StaticHandler() http.Handler {
sub, err := fs.Sub(staticFS, "ui/static")
if err != nil {
panic(err)
}
return http.FileServer(http.FS(sub))
}