about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFranck Cuny <franck@lumberjaph.net>2013-04-29 20:53:09 -0700
committerFranck Cuny <franck@lumberjaph.net>2013-04-29 20:53:09 -0700
commit0392a4d5debf777a30579bcfd7e9e47cd94109b4 (patch)
tree603465b6e6993c61aca525b36e6a6b92547e6c50
parentgofmt (diff)
downloadpath-router-0392a4d5debf777a30579bcfd7e9e47cd94109b4.tar.gz
Add a one line documentation for the public methods in the router
-rw-r--r--router.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/router.go b/router.go
index 41b1fc8..4eab24e 100644
--- a/router.go
+++ b/router.go
@@ -16,12 +16,14 @@ type Router struct {
 
 var defaultHTTPMethods = []string{"GET", "HEAD", "PUT", "POST", "PATCH", "OPTIONS"}
 
+// Create a new router.
 func BuildRouter() *Router {
 	router := Router{}
 	router.knownPaths = map[string]map[string]bool{}
 	return &router
 }
 
+// For each path, add a new route to respond to OPTIONS.
 func (self *Router) AddOptions() *Router {
 	self.withOptions = true
 	routes := self.GetRouteList()
@@ -38,6 +40,7 @@ func (self *Router) AddOptions() *Router {
 	return self
 }
 
+// For each path, add a route to respond 405 if the method is not implemented.
 func (self *Router) AddNotAllowed() *Router {
 	self.notAllowed = true
 	routes := self.GetRouteList()
@@ -72,6 +75,7 @@ func (self *Router) routeIsKnown(route *Route) bool {
 	return true
 }
 
+// Add a route to the router.
 func (self *Router) AddRoute(route *Route) error {
 	if self.routeIsKnown(route) == true {
 		return errors.New(fmt.Sprintf("The route %s with the method %s already exist.", route.Path, route.Method))
@@ -83,6 +87,7 @@ func (self *Router) AddRoute(route *Route) error {
 	return nil
 }
 
+// Will try to find a route that match the HTTP Request.
 func (self *Router) Match(request *http.Request) (*Match, error) {
 
 	matches := []*Match{}
@@ -133,6 +138,7 @@ func (self *Router) disambiguateMatches(path string, matches []*Match) (*Match,
 	return found[0], nil
 }
 
+// Get a list of routes from the router.
 func (self *Router) GetRouteList() []string {
 	routes := make([]string, len(self.knownPaths))
 	i := 0
@@ -143,6 +149,7 @@ func (self *Router) GetRouteList() []string {
 	return routes
 }
 
+// Check that the router knows a given path.
 func (self *Router) HasPath(path string) bool {
 	if self.knownPaths[path] != nil {
 		return true
@@ -150,6 +157,7 @@ func (self *Router) HasPath(path string) bool {
 	return false
 }
 
+// Remove a path (and all associated routes) from the router.
 func (self *Router) RemovePath(path string) error {
 	p := self.HasPath(path)
 	if p == false {
@@ -168,10 +176,12 @@ func (self *Router) RemovePath(path string) error {
 	return nil
 }
 
+// Return all the routes known by the router.
 func (self *Router) GetAllRoutes() []*Route {
 	return self.routes
 }
 
+// Return all the routes that implement the given HTTP method.
 func (self *Router) GetAllRoutesByMethods(method string) []*Route {
 	routes := []*Route{}
 	for _, r := range self.routes {
@@ -182,6 +192,7 @@ func (self *Router) GetAllRoutesByMethods(method string) []*Route {
 	return routes
 }
 
+// Return a list of HTTP methods implemented for a given path.
 func (self *Router) GetMethodsForPath(path string) []string {
 	p := self.knownPaths[path]
 	m := make([]string, len(p))