A HTTP router implemented in Golang
r := router.NewRouter()
r.MiddlewareFunc(func(w http.ResponseWriter, r *http.Request) {
// do something
})
r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
// do something
}).MiddlewareFunc(func(w http.ResponseWriter, r *http.Request) {
// do something
}).Methods("GET", "POST")
r.HookFunc(route.HookBeforeRouter, func(w http.ResponseWriter, r *http.Request) {
// do something
})
r.HookFunc(route.HookAfterDispatch, func(w http.ResponseWriter, r *http.Request) {
// do something
})
UrlFor()
method lest you dynamically create URLs for a named route
r.HandleFunc("/user/profile/query/<int:user_id>/", func(w http.ResponseWriter, r *http.Request) {
// do something
}).Name("profile")
if urls, ok := r.UrlFor("profile", map[string]interface{}{"user_id": 100001}); ok {
println(urls)
}
if err := http.ListenAndServe(":9090", r); err != nil {
// do something
}