about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFranck Cuny <franck@lumberjaph.net>2013-04-27 10:03:43 -0700
committerFranck Cuny <franck@lumberjaph.net>2013-04-27 10:03:43 -0700
commit89c722d8cb9ae27a1c701ced674df8795c5bd4fe (patch)
treed9ecd9133b4adae9ef635188820b8a9431e538a5
parentRename a few files. (diff)
downloadpath-router-89c722d8cb9ae27a1c701ced674df8795c5bd4fe.tar.gz
Rename all instances of Dispatcher to Router.
-rw-r--r--eg/base.go2
-rw-r--r--mooh.go2
-rw-r--r--request_test.go6
-rw-r--r--route_test.go12
-rw-r--r--router.go14
-rw-r--r--router_benchmark_test.go2
-rw-r--r--router_test.go8
7 files changed, 23 insertions, 23 deletions
diff --git a/eg/base.go b/eg/base.go
index cca4e40..4f4aa35 100644
--- a/eg/base.go
+++ b/eg/base.go
@@ -36,7 +36,7 @@ func TestPut(req *mooh.Request) (mooh.Response, error) {
 }
 
 func main() {
-	router := mooh.BuildDispatcher()
+	router := mooh.BuildRouter()
 
 	router.AddRoute(
 		&mooh.Route{
diff --git a/mooh.go b/mooh.go
index 2bcca75..3733b58 100644
--- a/mooh.go
+++ b/mooh.go
@@ -5,7 +5,7 @@ import (
 	"net/http"
 )
 
-func (self *Dispatcher) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
+func (self *Router) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
 
 	match, err := self.Match(req)
 
diff --git a/request_test.go b/request_test.go
index c4ad3d5..9062e78 100644
--- a/request_test.go
+++ b/request_test.go
@@ -12,8 +12,8 @@ func testRequestRoute(req *Request) (Response, error) {
 	return resp, nil
 }
 
-func buildDispatcher() Dispatcher {
-	router := BuildDispatcher()
+func buildRouter() Router {
+	router := BuildRouter()
 	router.AddRoute(&Route{
 		Method: "GET",
 		Path:   "/foo/:bar",
@@ -26,7 +26,7 @@ func buildDispatcher() Dispatcher {
 }
 
 func TestBasicRequest(t *testing.T) {
-	router := buildDispatcher()
+	router := buildRouter()
 	t.Log(router.routes[0].components)
 	r := &http.Request{Method: "GET", URL: &url.URL{Path: "/foo/bar"}}
 	m, _ := router.Match(r)
diff --git a/route_test.go b/route_test.go
index 1a03764..77a0092 100644
--- a/route_test.go
+++ b/route_test.go
@@ -14,7 +14,7 @@ func testRoute(req *Request) (Response, error) {
 }
 
 func TestBasic(t *testing.T) {
-	router := BuildDispatcher()
+	router := BuildRouter()
 	router.AddRoute(&Route{Method: "GET", Path: "/", Code: testRoute})
 	router.AddRoute(&Route{
 		Method: "GET",
@@ -40,7 +40,7 @@ func TestBasic(t *testing.T) {
 }
 
 func TestWithSimleValidation(t *testing.T) {
-	router := BuildDispatcher()
+	router := BuildRouter()
 	router.AddRoute(&Route{
 		Path:   "/users/:id",
 		Method: "GET",
@@ -78,7 +78,7 @@ func TestWithSimleValidation(t *testing.T) {
 }
 
 func TestMatch(t *testing.T) {
-	router := BuildDispatcher()
+	router := BuildRouter()
 	router.AddRoute(&Route{
 		Method: "GET",
 		Path:   "/blog/:year/:month/:day",
@@ -109,7 +109,7 @@ func TestMatch(t *testing.T) {
 }
 
 func TestMatchOptional(t *testing.T) {
-	router := BuildDispatcher()
+	router := BuildRouter()
 	router.AddRoute(&Route{
 		Path:   "/blog/?:year",
 		Method: "GET",
@@ -146,7 +146,7 @@ func TestMatchOptional(t *testing.T) {
 }
 
 func TestAmbigiousSimple(t *testing.T) {
-	router := BuildDispatcher()
+	router := BuildRouter()
 	router.AddRoute(&Route{Path: "/foo/bar", Method: "GET", Code: testRoute})
 	router.AddRoute(&Route{
 		Path:   "/foo/:bar",
@@ -167,7 +167,7 @@ func TestAmbigiousSimple(t *testing.T) {
 }
 
 func TestAmbigiousFail(t *testing.T) {
-	router := BuildDispatcher()
+	router := BuildRouter()
 	router.AddRoute(&Route{
 		Path:   "/foo/:bar",
 		Method: "GET",
diff --git a/router.go b/router.go
index e5c8e13..8612ad2 100644
--- a/router.go
+++ b/router.go
@@ -7,18 +7,18 @@ import (
 	"strings"
 )
 
-type Dispatcher struct {
+type Router struct {
 	routes     []*Route
 	knownPaths map[string]map[string]bool
 }
 
-func BuildDispatcher() Dispatcher {
-	router := Dispatcher{}
+func BuildRouter() Router {
+	router := Router{}
 	router.knownPaths = map[string]map[string]bool{}
 	return router
 }
 
-func (self *Dispatcher) routeIsKnown(route *Route) bool {
+func (self *Router) routeIsKnown(route *Route) bool {
 	if self.knownPaths[route.Path] == nil {
 		self.knownPaths[route.Path] = map[string]bool{}
 		return false
@@ -28,7 +28,7 @@ func (self *Dispatcher) routeIsKnown(route *Route) bool {
 	return true
 }
 
-func (self *Dispatcher) AddRoute(route *Route) error {
+func (self *Router) AddRoute(route *Route) error {
 	if self.routeIsKnown(route) == true {
 		return errors.New(fmt.Sprintf("Can't add twice the same route. The route %s with the method %s is already added", route.Path, route.Method))
 	}
@@ -39,7 +39,7 @@ func (self *Dispatcher) AddRoute(route *Route) error {
 	return nil
 }
 
-func (self *Dispatcher) Match(request *http.Request) (*Match, error) {
+func (self *Router) Match(request *http.Request) (*Match, error) {
 
 	matches := []*Match{}
 
@@ -63,7 +63,7 @@ func (self *Dispatcher) Match(request *http.Request) (*Match, error) {
 	return nil, nil
 }
 
-func (self *Dispatcher) disambiguateMatches(path string, matches []*Match) (*Match, error) {
+func (self *Router) disambiguateMatches(path string, matches []*Match) (*Match, error) {
 	min := -1
 	found := []*Match{}
 
diff --git a/router_benchmark_test.go b/router_benchmark_test.go
index 6c328ce..a5d334a 100644
--- a/router_benchmark_test.go
+++ b/router_benchmark_test.go
@@ -14,7 +14,7 @@ func testSimpleRoute(req *Request) (Response, error) {
 
 func BenchmarkSimple(b *testing.B) {
 	b.StopTimer()
-	router := BuildDispatcher()
+	router := BuildRouter()
 
 	// Most of the test is a rip from https://github.com/ant0ine/go-json-rest/
 	// author Antoine Imbert
diff --git a/router_test.go b/router_test.go
index 845833c..df67607 100644
--- a/router_test.go
+++ b/router_test.go
@@ -4,18 +4,18 @@ import (
 	"testing"
 )
 
-func testDispatcher (req *Request) (Response, error) {
+func testRouter (req *Request) (Response, error) {
 	resp := Response{}
 	return resp, nil
 }
 
 func testBasic(t *testing.T) {
-	d := BuildDispatcher()
-	err := d.AddRoute(&Route{Method:"GET", Path:"/", Code: testDispatcher})
+	d := BuildRouter()
+	err := d.AddRoute(&Route{Method:"GET", Path:"/", Code: testRouter})
 	if err != nil {
 		t.Fatal()
 	}
-	err = d.AddRoute(&Route{Method: "GET", Path:"/", Code: testDispatcher})
+	err = d.AddRoute(&Route{Method: "GET", Path:"/", Code: testRouter})
 	if err == nil {
 		t.Fatal()
 	}