saquibmian / regexrouter

regexrouter is a golang router

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

regexrouter

regexrouter is a golang router

Usage

Usage looks like this:

subrouter := regexrouter.NewRouter()
subrouter.Handle("^/builds/?$", map[string]http.Handler{
    http.MethodGet:  http.HandlerFunc(getRecentBuildsHandler),
    http.MethodPost: http.HandlerFunc(createBuildHandler),
})
subrouter.Handle("^/builds/([0-9]+)/?$", map[string]http.Handler{
    http.MethodGet: http.HandlerFunc(getBuildByIDHandler),
})

router := regexrouter.NewRouter()
router.HandleAny("^/builds/", subrouter)
router.HandleAny("^/", http.HandlerFunc(rootHandler))

You can also use named capture groups and access them through http.Request.Context().

About

regexrouter is a golang router

License:Apache License 2.0


Languages

Language:Go 100.0%