aboutsummaryrefslogtreecommitdiff
path: root/pkg/handler/router.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/handler/router.go')
-rw-r--r--pkg/handler/router.go36
1 files changed, 17 insertions, 19 deletions
diff --git a/pkg/handler/router.go b/pkg/handler/router.go
index bf13ad5..3da812f 100644
--- a/pkg/handler/router.go
+++ b/pkg/handler/router.go
@@ -20,9 +20,9 @@ func MountHandler(
configRepo *serverconfig.ConfigurationRepository,
) (http.Handler, error) {
var (
- gitHandler = git.NewGitHandler(gitService, configRepo)
- aboutHandler = about.NewAboutHandler(configRepo)
- configHander = config.ConfigFile(configRepo)
+ gitHandler = git.NewGitHandler(gitService, configRepo)
+ aboutHandler = about.NewAboutHandler(configRepo)
+ configHandler = config.ConfigFile(configRepo)
)
staticHandler, err := static.ServeStaticHandler()
@@ -30,21 +30,19 @@ func MountHandler(
return nil, err
}
- mux := http.NewServeMux()
+ mux := ext.NewRouter()
+ mux.AddMiddleware(ext.Compress)
+ mux.AddMiddleware(ext.Log)
- mux.HandleFunc("/static/{file}", m(staticHandler))
- mux.HandleFunc("/{name}/about/{$}", m(gitHandler.About))
- mux.HandleFunc("/{name}", m(gitHandler.Summary))
- mux.HandleFunc("/{name}/refs/{$}", m(gitHandler.Refs))
- mux.HandleFunc("/{name}/tree/{ref}/{rest...}", m(gitHandler.Tree))
- mux.HandleFunc("/{name}/blob/{ref}/{rest...}", m(gitHandler.Blob))
- mux.HandleFunc("/{name}/log/{ref}", m(gitHandler.Log))
- mux.HandleFunc("/config", m(configHander))
- mux.HandleFunc("/about", m(aboutHandler.About))
- mux.HandleFunc("/", m(gitHandler.List))
- return mux, nil
-}
-
-func m(next func(w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request) {
- return ext.Compress(next)
+ mux.HandleFunc("/static/{file}", staticHandler)
+ mux.HandleFunc("/{name}/about/{$}", gitHandler.About)
+ mux.HandleFunc("/{name}", gitHandler.Summary)
+ mux.HandleFunc("/{name}/refs/{$}", gitHandler.Refs)
+ mux.HandleFunc("/{name}/tree/{ref}/{rest...}", gitHandler.Tree)
+ mux.HandleFunc("/{name}/blob/{ref}/{rest...}", gitHandler.Blob)
+ mux.HandleFunc("/{name}/log/{ref}", gitHandler.Log)
+ mux.HandleFunc("/config", configHandler)
+ mux.HandleFunc("/about", aboutHandler.About)
+ mux.HandleFunc("/", gitHandler.List)
+ return mux.Handler(), nil
}