feat(go): M6.1 — template skeleton, embed.FS, HTML routes
All checks were successful
Deploy to K8s / deploy (push) Successful in 7s
All checks were successful
Deploy to K8s / deploy (push) Successful in 7s
Stand up the Go-native HTML frontend foundation: - base.tmpl layout + nav/footer partials (three-tier nav, active-link highlighting) - terminal-green-on-black theme extracted to static/css/app.css (served via embed.FS) - HTMLHandler with stub pages for all five routes; / redirects to /adults - NewRenderer parses per-page template sets at startup so parse failures abort boot - Smoke test: each route returns 200 text/html with exactly one class="active" link Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"fuj-management/go/internal/services/membership"
|
||||
"fuj-management/go/internal/web/api"
|
||||
"fuj-management/go/internal/web/middleware"
|
||||
"io/fs"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
)
|
||||
@@ -19,7 +20,12 @@ type BuildInfo struct {
|
||||
|
||||
// Run registers routes and starts the HTTP server on addr.
|
||||
func Run(logger *slog.Logger, addr string, build BuildInfo, sources membership.Sources, cfg config.Config) error {
|
||||
h := &api.Handler{
|
||||
renderer, err := NewRenderer()
|
||||
if err != nil {
|
||||
return fmt.Errorf("init templates: %w", err)
|
||||
}
|
||||
|
||||
ah := &api.Handler{
|
||||
BuildVersion: build.Version,
|
||||
BuildCommit: build.Commit,
|
||||
BuildDate: build.BuildDate,
|
||||
@@ -27,22 +33,34 @@ func Run(logger *slog.Logger, addr string, build BuildInfo, sources membership.S
|
||||
Config: cfg,
|
||||
Logger: logger,
|
||||
}
|
||||
hh := NewHTMLHandler(renderer, build)
|
||||
|
||||
staticSubFS, err := fs.Sub(staticFS, "static")
|
||||
if err != nil {
|
||||
return fmt.Errorf("static subfs: %w", err)
|
||||
}
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("GET /{$}", helloHandler(build))
|
||||
mux.HandleFunc("GET /api/version", h.ServeVersion)
|
||||
mux.HandleFunc("GET /api/adults", h.ServeAdults)
|
||||
mux.HandleFunc("GET /api/juniors", h.ServeJuniors)
|
||||
mux.HandleFunc("GET /api/payments", h.ServePayments)
|
||||
|
||||
// HTML routes
|
||||
mux.HandleFunc("GET /{$}", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, "/adults", http.StatusFound)
|
||||
})
|
||||
mux.HandleFunc("GET /adults", hh.ServeAdults)
|
||||
mux.HandleFunc("GET /juniors", hh.ServeJuniors)
|
||||
mux.HandleFunc("GET /payments", hh.ServePayments)
|
||||
mux.HandleFunc("GET /sync-bank", hh.ServeSync)
|
||||
mux.HandleFunc("GET /flush-cache", hh.ServeFlushCache)
|
||||
|
||||
// Static files
|
||||
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServerFS(staticSubFS)))
|
||||
|
||||
// JSON API routes
|
||||
mux.HandleFunc("GET /api/version", ah.ServeVersion)
|
||||
mux.HandleFunc("GET /api/adults", ah.ServeAdults)
|
||||
mux.HandleFunc("GET /api/juniors", ah.ServeJuniors)
|
||||
mux.HandleFunc("GET /api/payments", ah.ServePayments)
|
||||
|
||||
logger.Info("starting server", "addr", addr)
|
||||
return http.ListenAndServe(addr, middleware.RequestTimer(logger, mux))
|
||||
}
|
||||
|
||||
func helloHandler(build BuildInfo) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||
fmt.Fprintf(w, "fuj-go ok\nversion: %s\ncommit: %s\nbuilt: %s\n",
|
||||
build.Version, build.Commit, build.BuildDate)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user