Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Handlers ¶
Handlers map Handler keys to http.Handler objects. The Handler key is used to then match the Handler to the appropriate Route in the Router.
type Params ¶
Params map path keys to values. For example, if your route has the path pattern:
/person/:person_id/pets/:pet_type
Then a correct Params map would lool like:
router.Params{ "person_id": "123", "pet_type": "cats", }
type RequestGenerator ¶
func NewRequestGenerator ¶
func NewRequestGenerator(host string, routes Routes) *RequestGenerator
func (*RequestGenerator) RequestForHandler ¶
type Route ¶
type Route struct { // Handler is a key specifying which HTTP handler the router // should associate with the endpoint at runtime. Handler string // Method is one of the following: GET,PUT,POST,DELETE Method string // Path contains a path pattern Path string }
A Route defines properties of an HTTP endpoint. At runtime, the router will associate each Route with a http.Handler object, and use the Route properties to determine which Handler should be invoked.
Currently, properties used in match are such as Method and Path.
Method is one of the following:
GET PUT POST DELETE
Path conforms to Pat-style pattern matching. The following docs are taken from http://godoc.org/github.com/bmizerany/pat#PatternServeMux
Path Patterns may contain literals or captures. Capture names start with a colon and consist of letters A-Z, a-z, _, and 0-9. The rest of the pattern matches literally. The portion of the URL matching each name ends with an occurrence of the character in the pattern immediately following the name, or a /, whichever comes first. It is possible for a name to match the empty string.
Example pattern with one capture:
/hello/:name
Will match:
/hello/blake /hello/keith
Will not match:
/hello/blake/ /hello/blake/foo /foo /foo/bar
Example 2:
/hello/:name/
Will match:
/hello/blake/ /hello/keith/foo /hello/blake /hello/keith
Will not match:
/foo /foo/bar
type Routes ¶
type Routes []Route
Routes is a Route collection.
func (Routes) PathForHandler ¶
PathForHandler looks up a Route by it's Handler key and computes it's path with a given Params map.
func (Routes) RouteForHandler ¶
RouteForHandler looks up a Route by it's Handler key.