mirror of
https://github.com/cubixle/tuu.git
synced 2026-04-24 21:34:42 +01:00
SAVEPOINT
This commit is contained in:
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
2
route.go
2
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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user