【发布时间】:2017-04-29 00:26:45
【问题描述】:
当我使用http 的默认路由器时,一切正常,但如果我使用gorilla/mux 的路由器,我会得到一个正文为404 page not found 的404 页面。如以下示例所示,其他一切都完全相同。
为什么gorilla/mux 路由器不能这样工作?
工作正常,使用http路由:
package main
import "net/http"
func simplestPossible(w http.ResponseWriter, req *http.Request) {
w.Write([]byte("MWE says OK"))
}
func main() {
http.HandleFunc("/", simplestPossible)
http.ListenAndServe(":8000", nil)
}
不工作,使用gorilla/mux路由:
package main
import "net/http"
import "github.com/gorilla/mux"
func simplestPossible(w http.ResponseWriter, req *http.Request) {
w.Write([]byte("MWE says OK"))
}
func main() {
r := mux.NewRouter()
r.HandleFunc("/", simplestPossible)
http.ListenAndServe(":8000", nil)
}
【问题讨论】: