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)
}
How does 'PathPrefix' work in 'gorilla.mux' library for Go?
문제
I'm playing around with the gorilla.mux
library for Go. I have the following configuration, but I cant figure out the URL to reach the HelloWorldXml
method.
func main() {
router := mux.NewRouter()
router.HandleFunc("/{name}.xml", HelloWorldXml).
PathPrefix("/products/")
router.HandleFunc("/hello/{name}", HelloWorld)
http.Handle("/", router)
http.ListenAndServe(":8787",nil)
}
What would be the proper URL to use? http://localhost:8787/products/MyName.xml
returns a 404.
해결책
제휴하지 않습니다 StackOverflow