about summary refs log tree commit diff
path: root/route.go (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Add GetPath and GetMethod to the Match object masterFranck Cuny2013-05-121-4/+12
|
* The Match type implement an interface.Franck Cuny2013-05-121-2/+6
| | | | | The "mapping" field that contains the map of elements in the path is now private and can be accesed via the RouteParams function.
* FmtFranck Cuny2013-05-111-3/+3
|
* The response object is passed to the matching function.Franck Cuny2013-05-111-3/+3
| | | | | | Instead of letting the matching function creates the response object, it's created earlier with a default HTTP status of 200, and the object is passed to the function.
* Rename the package from mooh to routerFranck Cuny2013-05-081-1/+1
|
* Remove code not related to the router.Franck Cuny2013-05-061-2/+3
| | | | | | | | `foom` is now the web framework, so the code from mooh.go has been moved to that repository. The response and request are handled by the new `web-request` project, and so the code has been moved to this repository.
* Placeholder in URL use the {\w+} form, not :\w+Franck Cuny2013-04-271-4/+4
| | | | | This is the format supported for URI templates (RFC 6570). We're not using it now but this is something that I consider for a near future.
* Support default value for placeholders in route's path.Franck Cuny2013-04-271-2/+9
| | | | | | | | | | | | | | | If a route is created with a Default: &Route{ Path: "/user/:id", Defaults: map[string]string{ "id": "1", }, ... } a request for /user/ will match the route, and set the value for "id" to 1. However, the route /user will not match.
* Add Validations for URL parameters.Franck Cuny2013-04-261-10/+67
| | | | | | | | | | | | | | By adding validations, it's possible to create without ambiguity routes like "/user/:id" and "/user/:name", where the validation for the name will check that it's an number, and name is a string. A validation is not required for every key. However, you can't specify a validation for a key that does not exist in the URL. The validation use Regexp for now, and the user has to create the regexp with the function MustCompile. Some utility functions are added to easily gain information about a component, validator, etc. This will be extended more soon.
* Change the interface to create routes.Franck Cuny2013-04-221-38/+25
| | | | | | | | | | | | Previously, to create a route, a user would call the AddRoute function, and pass three arguments (the path, the HTTP method and the function). This interface is way too limited if we need/want to expand what a route is in the future. Instead, we keep calling the AddRoute function to create a route, but this time the user pass a Route structure. The AddRoute will then apply a few transformations and connect the route to the router.
* In each route, keep a map of HTTP methods available.Franck Cuny2013-04-221-7/+4
| | | | | | By keeping a map of the HTTP methods available for a given route, we don't have to iter over a list of executors when we try to find if the request match, we can quickly check if the methos is set to true.
* Split only once per request the path in components.Franck Cuny2013-04-221-6/+4
| | | | | | | | | | | There's no need to split the URL in components every time we call the Match function on a Route. We can split it once in the dispatcher and then path the array to the function. Sadly, this makes the interface a little bit weaker, since we have to pass the HTTP method and the list instead of the full HTTP Request. I think in the future we should pass our own HTTP request object, with the split already in done in this one.
* Apply gofmtFranck Cuny2013-04-211-1/+0
|
* Normalize the name of captured components.Franck Cuny2013-04-211-2/+9
| | | | | | In the case of an optional components, the name is ":something". We need to normalize that name in order to be able to call directly "something" when needed.
* Apply gofmtFranck Cuny2013-04-211-1/+1
|
* Simplify the dispatch's workflow.Franck Cuny2013-04-211-3/+4
| | | | | | | | Forward the http.Request object to the Dispatcher's Match function, and instead of returning the route that match, return the whole Match object. We create our own Request object later in the process.
* Rename the type fn to fns and add a real type fnFranck Cuny2013-04-211-4/+5
|
* Small improvementsFranck Cuny2013-04-211-5/+1
| | | | | Don't mess with the first / for now, we will see later if we need to change it.
* Disambiguate routes when more than one match.Franck Cuny2013-04-211-8/+6
| | | | | | | | | For some path, more than one route can match. We try hard to disambiguate them, and if we can't, we return an error with the list of routes matching the request. In order to do that, the Match function needs to be able to also return an error in addition to a route.
* Add support for optional parameter in a path.Franck Cuny2013-04-211-7/+17
| | | | | | If a component in the path starts with "?:", it means that it's optional. We then store the lenght of the components without those optional parameters.
* The test was inversed.Franck Cuny2013-04-211-1/+1
|
* Clean the Path from useless /.Franck Cuny2013-04-211-1/+7
| | | | If a path starts with /, remove it.
* Support parameters in URL.Franck Cuny2013-04-211-16/+57
| | | | | | | | | | | | | | When creating a new route, check if the URL contains some elements with a ":" in it. If that's the case, it means that this component is a parameter. For now we consider that all the parameters are required, but in the future we should support optional parameters (starting with a ?). When dispatching a request, verify if the element in the url is a parameter and store it in the response. When a route match a request, a Match structure is returned with some information (path that matched, the route, the HTTP method, etc.).
* Very simple implementation for the framework.Franck Cuny2013-04-171-0/+61
For now the framework provide a "dispatcher" and a mechanism to add routes. The type "route" provide a constructor so some logic can be applied before creating the type. The way the dispatcher works for now is very stupid: it looks for all the registered routes, and check if it's the right HTTP method and if the patch matches. The next step is to deal with place holder in the path.