feat: add diagnostic web app shell

This commit is contained in:
user
2026-04-26 18:39:09 +09:00
parent 3493f8b5a5
commit ce38189f33
15 changed files with 763 additions and 9 deletions

41
internal/webapp/assets.go Normal file
View File

@@ -0,0 +1,41 @@
package webapp
import (
"embed"
"io/fs"
"net/http"
"strings"
)
//go:embed static/*
var assets embed.FS
func Handler() http.Handler {
static, err := fs.Sub(assets, "static")
if err != nil {
panic(err)
}
files := http.FileServer(http.FS(static))
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/" {
serveIndex(w, r, static)
return
}
if strings.HasPrefix(r.URL.Path, "/assets/") {
http.StripPrefix("/assets/", files).ServeHTTP(w, r)
return
}
http.NotFound(w, r)
})
}
func serveIndex(w http.ResponseWriter, r *http.Request, static fs.FS) {
content, err := fs.ReadFile(static, "index.html")
if err != nil {
http.Error(w, "web app unavailable", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
_, _ = w.Write(content)
}