当我使用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)
}