From 2f157585d6cad99cd821f11baab06cf68483f971 Mon Sep 17 00:00:00 2001 From: "luke.rodham" Date: Mon, 13 Nov 2017 15:12:13 +0000 Subject: [PATCH] SAVEPOINT --- default_router.go | 20 ++++++++++++++++++-- route.go | 2 ++ router.go | 2 ++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/default_router.go b/default_router.go index 7114aa8..f79b120 100644 --- a/default_router.go +++ b/default_router.go @@ -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, }) } diff --git a/route.go b/route.go index 95a0898..ab71b96 100644 --- a/route.go +++ b/route.go @@ -1,6 +1,7 @@ package tuu import ( + "github.com/gorilla/mux" "net/http" gcontext "github.com/gorilla/context" @@ -10,6 +11,7 @@ type Route struct { Method string Path string Handler Handler + MuxHandler mux.Route } func (r *Route) ServeHTTP(res http.ResponseWriter, req *http.Request) { diff --git a/router.go b/router.go index ab70a5b..6e86e24 100644 --- a/router.go +++ b/router.go @@ -5,9 +5,11 @@ import "net/http" type Handler func(Context) error type Router interface { + Prefix(path string) GET(path string, h Handler) POST(path string, h Handler) Static(path string, root http.FileSystem) + NotFound(path string. h Handler) GetRoutes() []*Route GetStaticRoutes() []*StaticRoute