Commit 6372e221 by bergquist Committed by Carl Bergquist

migrate handlers to new register

parent f8422653
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
) )
type Router interface { type Router interface {
Route(pattern, method string, handlers ...macaron.Handler) Handle(method, pattern string, handlers []macaron.Handler) *macaron.Route
} }
type RouteRegister interface { type RouteRegister interface {
...@@ -15,10 +15,12 @@ type RouteRegister interface { ...@@ -15,10 +15,12 @@ type RouteRegister interface {
Post(string, ...macaron.Handler) Post(string, ...macaron.Handler)
Delete(string, ...macaron.Handler) Delete(string, ...macaron.Handler)
Put(string, ...macaron.Handler) Put(string, ...macaron.Handler)
Patch(string, ...macaron.Handler)
Any(string, ...macaron.Handler)
Group(string, func(RouteRegister), ...macaron.Handler) Group(string, func(RouteRegister), ...macaron.Handler)
Register(Router) Register(Router) *macaron.Router
} }
func newRouteRegister() RouteRegister { func newRouteRegister() RouteRegister {
...@@ -53,17 +55,22 @@ func (rr *routeRegister) Group(pattern string, fn func(rr RouteRegister), handle ...@@ -53,17 +55,22 @@ func (rr *routeRegister) Group(pattern string, fn func(rr RouteRegister), handle
rr.groups = append(rr.groups, group) rr.groups = append(rr.groups, group)
} }
func (rr *routeRegister) Register(router Router) { func (rr *routeRegister) Register(router Router) *macaron.Router {
for _, r := range rr.routes { for _, r := range rr.routes {
router.Route(r.pattern, r.method, r.handlers...) router.Handle(r.method, r.pattern, r.handlers)
} }
for _, g := range rr.groups { for _, g := range rr.groups {
g.Register(router) g.Register(router)
} }
return &macaron.Router{}
} }
func (rr *routeRegister) route(pattern, method string, handlers ...macaron.Handler) { func (rr *routeRegister) route(pattern, method string, handlers ...macaron.Handler) {
//inject metrics
//inject tracing
rr.routes = append(rr.routes, route{ rr.routes = append(rr.routes, route{
method: method, method: method,
pattern: rr.prefix + pattern, pattern: rr.prefix + pattern,
...@@ -86,3 +93,11 @@ func (rr *routeRegister) Delete(pattern string, handlers ...macaron.Handler) { ...@@ -86,3 +93,11 @@ func (rr *routeRegister) Delete(pattern string, handlers ...macaron.Handler) {
func (rr *routeRegister) Put(pattern string, handlers ...macaron.Handler) { func (rr *routeRegister) Put(pattern string, handlers ...macaron.Handler) {
rr.route(pattern, http.MethodPut, handlers...) rr.route(pattern, http.MethodPut, handlers...)
} }
func (rr *routeRegister) Patch(pattern string, handlers ...macaron.Handler) {
rr.route(pattern, http.MethodPatch, handlers...)
}
func (rr *routeRegister) Any(pattern string, handlers ...macaron.Handler) {
rr.route(pattern, "*", handlers...)
}
...@@ -11,12 +11,14 @@ type fakeRouter struct { ...@@ -11,12 +11,14 @@ type fakeRouter struct {
route []route route []route
} }
func (fr *fakeRouter) Route(pattern, method string, handlers ...macaron.Handler) { func (fr *fakeRouter) Handle(method, pattern string, handlers []macaron.Handler) *macaron.Route {
fr.route = append(fr.route, route{ fr.route = append(fr.route, route{
pattern: pattern, pattern: pattern,
method: method, method: method,
handlers: handlers, handlers: handlers,
}) })
return &macaron.Route{}
} }
func emptyHandlers(n int) []macaron.Handler { func emptyHandlers(n int) []macaron.Handler {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment