1 回答
TA贡献1816条经验 获得超6个赞
net/http.Handle你不能混合gorilla/mux.Router
你可以这样做
func main() {
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static/"))))
http.HandleFunc("/index", index)
http.ListenAndServe(":8080", nil)
}
func index(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./static/html/test.html")
}
或者像这样
func main() {
r := mux.NewRouter()
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("./static/"))))
r.HandleFunc("/index", index)
http.ListenAndServe(":8080", r)
}
func index(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./static/html/test.html")
}
- 1 回答
- 0 关注
- 106 浏览
添加回答
举报