aboutsummaryrefslogtreecommitdiff
path: root/pkg/handler/router.go
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2024-05-30 18:04:49 +0200
committerGabriel A. Giovanini <mail@gabrielgio.me>2024-05-30 18:04:49 +0200
commitfb45f1f5002ffdb40150333c5a48458b801f3022 (patch)
treee83cab49735599e3adfb4557e229caa2f29ab7a7 /pkg/handler/router.go
parente52226c05fb54dfe41c9bc5ebc6ce1b7ded7e1fe (diff)
downloadcerrado-fb45f1f5002ffdb40150333c5a48458b801f3022.tar.gz
cerrado-fb45f1f5002ffdb40150333c5a48458b801f3022.tar.bz2
cerrado-fb45f1f5002ffdb40150333c5a48458b801f3022.zip
ref: Move to gorilla mux
Go's default mux is very limited while comes to overlapping routes. For example "/{name}/about" conflicts with "/static/" and it throws a panic. In the case I would like static to have precedence over everything else.
Diffstat (limited to 'pkg/handler/router.go')
-rw-r--r--pkg/handler/router.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/pkg/handler/router.go b/pkg/handler/router.go
index 1150f2f..f73e9fb 100644
--- a/pkg/handler/router.go
+++ b/pkg/handler/router.go
@@ -9,6 +9,7 @@ import (
"git.gabrielgio.me/cerrado/pkg/handler/git"
"git.gabrielgio.me/cerrado/pkg/handler/static"
"git.gabrielgio.me/cerrado/pkg/service"
+ "github.com/gorilla/mux"
)
// Mount handler gets the requires service and repository to build the handlers
@@ -29,11 +30,16 @@ func MountHandler(
return nil, err
}
- mux := http.NewServeMux()
- mux.Handle("/static/", staticHandler)
+ mux := mux.NewRouter()
+
+ mux.PathPrefix("/static").Handler(staticHandler)
+ mux.HandleFunc("/{name}/about", gitHandler.About)
+ mux.HandleFunc("/{name}/summary", gitHandler.Summary)
+ mux.HandleFunc("/{name}/refs", gitHandler.Refs)
+ mux.HandleFunc("/{name}/tree", gitHandler.Tree)
+ mux.HandleFunc("/{name}/log", gitHandler.Log)
mux.HandleFunc("/config", configHander)
mux.HandleFunc("/about", aboutHandler.About)
- mux.HandleFunc("/{name}", gitHandler.Item)
mux.HandleFunc("/", gitHandler.List)
return mux, nil
}