package web import ( "embed" "io/fs" "net/http" "os" ) //go:embed static/* var staticFiles embed.FS type spaFileSystem struct { root http.FileSystem } func (spa *spaFileSystem) Open(name string) (http.File, error) { f, err := spa.root.Open(name) if os.IsNotExist(err) { return spa.root.Open("index.html") } return f, err } func initStatic(mux *http.ServeMux) { staticFS, _ := fs.Sub(staticFiles, "static") mux.Handle("/", http.FileServer(&spaFileSystem{http.FS(staticFS)})) }