當我寫這樣一個簡單的Web應用程序:獲取途徑,而params列表中Golang HTTP或大猩猩包
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應用程序定義的路由,而params名單? 例如在本例中找到「/ about」。
編輯1: 如何得到這一個參數和路線?
gorilla.HandleFunc(`/check/{id:[0-9]+}`, func(res http.ResponseWriter, req *http.Request) {
res.Write([]byte("Regexp works :)"))
})
需要什麼,你試圖解決這個問題? – Venkat
與大猩猩/多路複用器:你可以使用['router.Walk'](https://godoc.org/github.com/gorilla/mux#Router.Walk)來走路由器,然後調用['route.GetPathTemplate '](https://godoc.org/github.com/gorilla/mux#Route.GetPathTemplate)獲取該路線的模式。 – elithrar