我正在玩gorilla.muxGo的圖書館。我有以下配置,但我無法弄清楚到達(dá)該HelloWorldXml方法的 URL 。func main() { router := mux.NewRouter() router.HandleFunc("/{name}.xml", HelloWorldXml). PathPrefix("/products/") router.HandleFunc("/hello/{name}", HelloWorld) http.Handle("/", router) http.ListenAndServe(":8787",nil)}要使用的正確 URL 是什么? http://localhost:8787/products/MyName.xml返回 404。
1 回答

守著一只汪
TA貢獻(xiàn)1872條經(jīng)驗(yàn) 獲得超4個(gè)贊
func main() {
router := mux.NewRouter()
router.HandleFunc("/{name}.xml", HelloWorldXml)
subrouter := router.PathPrefix("/products/").Subrouter()
//localhost/products/item.xml
subrouter.HandleFunc("/{name}.xml", HelloWorldXmlHandler)
router.HandleFunc("/hello/{name}", HelloWorld)
http.Handle("/", router)
http.ListenAndServe(":8787",nil)
}
- 1 回答
- 0 關(guān)注
- 362 瀏覽
添加回答
舉報(bào)
0/150
提交
取消