この NotFoundHandler を機能させることができません。静的ファイルが存在する場合はすべての取得要求で静的ファイルを提供したいと思います。それ以外の場合は index.html を提供します。現時点での私の単純化されたルーターは次のとおりです。
func fooHandler() http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Foo"))
}
return http.HandlerFunc(fn)
}
func notFound(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "public/index.html")
}
func main() {
router = mux.NewRouter()
fs := http.FileServer(http.Dir("public"))
router.Handle("/foo", fooHandler())
router.PathPrefix("/").Handler(fs)
router.NotFoundHandler = http.HandlerFunc(notFound)
http.ListenAndServe(":3000", router)
}
/fooは正常に動作します
/file-that-existsは正常に動作します
/file-that-doesnt-exist が機能しない - index.html の代わりに 404 page not found が表示される
それで、私はここで何が間違っていますか?