Skip to content

Commit

Permalink
Perf: perf router
Browse files Browse the repository at this point in the history
  • Loading branch information
yangfei committed Feb 12, 2019
1 parent c292117 commit 8987fb4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 47 deletions.
24 changes: 11 additions & 13 deletions router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,18 @@ func (r *Router) DELETE(path string, handler decorates.Handler) {
}

func (r *Router) register(method, path string, handler decorates.Handler) {
route := &Route{
Method: method,
Handler: handler,
Pattern: path,
}
handler = route.Handler.
handler = handler.
CorsHeader().
Logger()

router.
Methods(route.Method).
Path(route.Pattern).
Methods(method).
Path(path).
Handler(handler)

router.
Methods("OPTIONS").
Path(route.Pattern).
Path(path).
Name("cors").
Handler(
decorates.Handler(
Expand All @@ -95,10 +92,11 @@ func (r *Router) register(method, path string, handler decorates.Handler) {
}

func New() *Router {
if router == nil {
router = &Router{
mux.NewRouter().StrictSlash(true),
}
if router != nil {
return router
}
router = &Router{
mux.NewRouter().StrictSlash(true),
}
return router
}
34 changes: 0 additions & 34 deletions router/routes.go

This file was deleted.

0 comments on commit 8987fb4

Please sign in to comment.