From d4eabf891ce67b01a6321a53115a3b360ebfc017 Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Sun, 12 May 2013 14:06:13 -0700 Subject: Add GetPath and GetMethod to the Match object --- route.go | 16 ++++++++++++---- route_test.go | 6 +++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/route.go b/route.go index 6c41c95..483f4e3 100644 --- a/route.go +++ b/route.go @@ -23,10 +23,10 @@ type Route struct { } type Match struct { - Path string + path string Route Route mapping map[string]string - Method string + method string } var componentIsVariable = regexp.MustCompile("^{[^}]+}$") @@ -38,6 +38,14 @@ func (self *Match) RouteParams() map[string]string { return self.mapping } +func (self *Match) GetPath() string { + return self.path +} + +func (self *Match) GetMethod() string { + return self.method +} + // XXX explain this function func (self *Route) convertComponentName(name string) string { newName := convertComponent.FindStringSubmatch(name) @@ -105,9 +113,9 @@ L: } return &Match{ - Path: strings.Join(components, "/"), + path: strings.Join(components, "/"), Route: *self, - Method: method, + method: method, mapping: mapping, } } diff --git a/route_test.go b/route_test.go index dd38e80..339a797 100644 --- a/route_test.go +++ b/route_test.go @@ -103,7 +103,7 @@ func TestMatch(t *testing.T) { if m == nil { t.Fatal() } else { - fmt.Println(fmt.Sprintf("%s match for %s", p.Path, m.Path)) + fmt.Println(fmt.Sprintf("%s match for %s", p.Path, m.GetPath())) } } } @@ -140,7 +140,7 @@ func TestMatchOptional(t *testing.T) { if m == nil { t.Fatal() } else { - fmt.Println(fmt.Sprintf("%s match for %s", p.Path, m.Path)) + fmt.Println(fmt.Sprintf("%s match for %s", p.Path, m.GetPath())) } } } @@ -162,7 +162,7 @@ func TestAmbigiousSimple(t *testing.T) { if m == nil { t.Fatal() } else { - fmt.Println(fmt.Sprintf("%s match for %s", r.URL.Path, m.Path)) + fmt.Println(fmt.Sprintf("%s match for %s", r.URL.Path, m.GetPath())) } } -- cgit 1.4.1