【发布时间】:2017-10-30 21:56:21
【问题描述】:
我正在使用 gorilla serve mux 来提供静态 html 文件。
r := mux.NewRouter()
r.PathPrefix("/").Handler(http.FileServer(http.Dir("./public"))).Methods("GET")
我在公共文件夹中确实有一个 Index.html 文件以及其他 html 文件。
浏览网站时,我得到文件夹的所有内容,而不是默认的 Index.html。
我来自 C#,我知道 IIS 将 Index.html 作为默认值,但可以选择任何页面作为默认值。
我想知道是否有适当的方法来选择默认页面以在 Gorilla mux 中提供服务,而无需创建自定义处理程序/包装器。
【问题讨论】:
-
我不认为这是因为 Gorilla 多路复用器,而是因为
http.FileServer,在 docs 中它说As a special case, the returned file server redirects any request ending in "/index.html" to the same path, without the final "index.html". -
老兄,你应该把它作为答案发布,因为你解决了它!