Вопрос

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.

Это было полезно?

Решение

 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)
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top