Skip to content

zakzou/router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

router

A HTTP router implemented in Golang

Documentation

initialize

r := router.NewRouter()

register middleware for all route

r.MiddlewareFunc(func(w http.ResponseWriter, r *http.Request) {
    // do something
})

register middleware for a route

r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    // do something
}).MiddlewareFunc(func(w http.ResponseWriter, r *http.Request) {
    // do something
}).Methods("GET", "POST")

register hook

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
})

URL For

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)
}

run

if err := http.ListenAndServe(":9090", r); err != nil {
    // do something
}

License

MIT: http://rem.mit-license.org

About

A HTTP router implemented in Golang

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages