当我像这样编写一个简单的 Web 应用程序时:
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
}
func main() {
http.HandleFunc("/about", handler)
http.ListenAndServe(":8080", nil)
}
如何找到我在 Web 应用程序中定义的路线和参数列表?例如,在本例中查找“/about”。
编辑1: 如何获得这个参数和路线?
gorilla.HandleFunc(`/check/{id:[0-9]+}`, func(res http.ResponseWriter, req *http.Request) {
res.Write([]byte("Regexp works :)"))
})