SAVEPOINT

This commit is contained in:
luke.rodham
2017-11-13 15:12:13 +00:00
parent 866e0da047
commit 2f157585d6
3 changed files with 22 additions and 2 deletions

View File

@@ -1,6 +1,10 @@
package tuu
import "net/http"
import (
"fmt"
"net/http"
"strings"
)
func NewRouter() *DefaultRouter {
return &DefaultRouter{}
@@ -9,6 +13,12 @@ func NewRouter() *DefaultRouter {
type DefaultRouter struct {
Routes []*Route
StaticRoutes []*StaticRoute
prefix string
}
func (r *Prefix) Prefix(path string) {
r.prefix = path
}
func (r *DefaultRouter) GET(path string, h Handler) {
@@ -26,6 +36,10 @@ func (r *DefaultRouter) Static(path string, root http.FileSystem) {
})
}
func (r *DefaultRouter) NotFound(path string, h Handler) {
}
func (r *DefaultRouter) GetRoutes() []*Route {
return r.Routes
}
@@ -35,9 +49,11 @@ func (r *DefaultRouter) GetStaticRoutes() []*StaticRoute {
}
func (r *DefaultRouter) addRoute(m, p string, h Handler) {
path := fmt.Sprintf("/%s/%s", strings.TrimPrefix(r.prefix, "/"), strings.TrimSuffix(p, "/"))
r.Routes = append(r.Routes, &Route{
Method: m,
Path: p,
Path: path,
Handler: h,
})
}