about summary refs log tree commit diff
path: root/route.go
diff options
context:
space:
mode:
authorFranck Cuny <franck@lumberjaph.net>2013-04-21 16:00:22 -0700
committerFranck Cuny <franck@lumberjaph.net>2013-04-21 16:00:22 -0700
commit236f53dfceb995b528e43f0e0b138e22a9c3b0a6 (patch)
tree77c238b8d9de49b9f6d56e49a16464a3cf476fc5 /route.go
parentRename the type fn to fns and add a real type fn (diff)
downloadpath-router-236f53dfceb995b528e43f0e0b138e22a9c3b0a6.tar.gz
Simplify the dispatch's workflow.
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.
Diffstat (limited to 'route.go')
-rw-r--r--route.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/route.go b/route.go
index 768315e..f17fe7b 100644
--- a/route.go
+++ b/route.go
@@ -3,6 +3,7 @@ package mooh
 import (
 	"regexp"
 	"strings"
+	"net/http"
 )
 
 type fn func(*Request) (Response, error)
@@ -29,7 +30,7 @@ var componentIsVariable = regexp.MustCompile("^:")
 var componentsIsOptional = regexp.MustCompile("^?:")
 var namedComponentsRegex = regexp.MustCompile("^:(.*)$")
 
-func (self *Route) Match(request Request) *Match {
+func (self *Route) Match(request *http.Request) *Match {
 	methodMatch := false
 	for m, _ := range self.Executors {
 		if m == request.Method {
@@ -40,7 +41,7 @@ func (self *Route) Match(request Request) *Match {
 		return nil
 	}
 
-	components := strings.Split(request.Request.URL.Path, "/")
+	components := strings.Split(request.URL.Path, "/")
 	if len(components) < self.LengthWithoutOptional || len(components) > self.Length {
 		return nil
 	}
@@ -63,7 +64,7 @@ func (self *Route) Match(request Request) *Match {
 	}
 
 	return &Match{
-		Path:    request.Request.URL.Path,
+		Path:    request.URL.Path,
 		Route:   *self,
 		Method:  request.Method,
 		Mapping: mapping,