123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- /*
- The Kurz Web UI exposes HTTP routes for browsers, route names to access them, and types for the requests.
- These routes are exposed by running SetupRoutes(address), which is enough to
- configure the Kurz domain API. Be sure to also configure the domain SPI to have
- a complete application.
- */
- package web
- import "github.com/gorilla/mux"
- // Route names.
- const (
- RouteGetRoot = "kurz.web.get_root"
- RouteGetShort = "kurz.web.get_short"
- RoutePostTarget = "kurz.web.post_target"
- )
- // Content types.
- const (
- // HtmlType is the MIME HTML type.
- HtmlType = "text/html"
- // HtmlTypeRegex is a regex matching the MIME HTML type anywhere
- HtmlTypeRegex = HtmlType
- )
- // SetupRoutes treats s as UTF-8-encoded bytes and returns a copy with all Unicode letters that begin
- // words mapped to their title case.
- func SetupRoutes(router *mux.Router) {
- // BUG(fgm): improve Accept header matchers once https://github.com/golang/go/issues/19307 is completed.
- router.HandleFunc("/{short}", handleGetShort).
- HeadersRegexp("Accept", HtmlTypeRegex).
- Methods("GET", "HEAD").
- Name(RouteGetShort)
- router.HandleFunc("/", handlePostTarget).
- HeadersRegexp("Accept", HtmlTypeRegex).
- Headers("Content-Type", HtmlType).
- Methods("POST").
- Name(RoutePostTarget)
- router.HandleFunc("/", handleGetRoot).
- HeadersRegexp("Accept", HtmlTypeRegex).
- Methods("GET", "HEAD").
- Name(RouteGetRoot)
- }
|