web.go 595 B

12345678910111213141516171819202122232425
  1. package web
  2. import (
  3. "embed"
  4. "io/fs"
  5. "net/http"
  6. )
  7. //go:embed static/*
  8. var staticFS embed.FS
  9. // Handler returns an http.Handler that serves the embedded web dashboard with no-cache headers.
  10. func Handler() http.Handler {
  11. sub, err := fs.Sub(staticFS, "static")
  12. if err != nil {
  13. panic(err)
  14. }
  15. fileServer := http.FileServer(http.FS(sub))
  16. return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  17. w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
  18. w.Header().Set("Pragma", "no-cache")
  19. w.Header().Set("Expires", "0")
  20. fileServer.ServeHTTP(w, r)
  21. })
  22. }