diff --git a/go.mod b/go.mod
index eabf863a1cad6dd1f4d7987411f42b61998c30f6..5bd4d7647b43cb737a873b5636a162a1ea25df69 100644
--- a/go.mod
+++ b/go.mod
@@ -8,7 +8,6 @@ github.com/alecthomas/chroma/v2 v2.13.0
github.com/go-git/go-git/v5 v5.12.0
github.com/gomarkdown/markdown v0.0.0-20240419095408-642f0ee99ae2
github.com/google/go-cmp v0.6.0
- github.com/gorilla/mux v1.8.1
github.com/valyala/quicktemplate v1.7.0
golang.org/x/sync v0.7.0
)
diff --git a/go.sum b/go.sum
index bc82b643fa7d12dfe3959e2d53a409f8defb51cb..69c34b73d113fa1f0ae49c5068a2517c3ee91725 100644
--- a/go.sum
+++ b/go.sum
@@ -51,8 +51,6 @@ github.com/gomarkdown/markdown v0.0.0-20240419095408-642f0ee99ae2 h1:yEt5djSYb4iNtmV9iJGVday+i4e9u6Mrn5iP64HH5QM=
github.com/gomarkdown/markdown v0.0.0-20240419095408-642f0ee99ae2/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
-github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
-github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
diff --git a/pkg/handler/git/handler.go b/pkg/handler/git/handler.go
index b77bcfc0e35d58f47b6fd5a08e74a23fa4d3735f..e2f40422ed212156620190800a9ec6569bc4c11f 100644
--- a/pkg/handler/git/handler.go
+++ b/pkg/handler/git/handler.go
@@ -8,7 +8,6 @@ "git.gabrielgio.me/cerrado/pkg/service"
"git.gabrielgio.me/cerrado/templates"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
- "github.com/gorilla/mux"
)
type (
@@ -43,7 +42,7 @@ templates.WritePageTemplate(w, gitList)
}
func (g *GitHandler) Summary(w http.ResponseWriter, r *http.Request) {
- name := mux.Vars(r)["name"]
+ name := r.PathValue("name")
ref, err := g.gitService.GetHead(name)
if err != nil {
slog.Error("Error loading head", "error", err)
@@ -59,7 +58,7 @@ templates.WritePageTemplate(w, gitList)
}
func (g *GitHandler) About(w http.ResponseWriter, r *http.Request) {
- name := mux.Vars(r)["name"]
+ name := r.PathValue("name")
ref, err := g.gitService.GetHead(name)
if err != nil {
slog.Error("Error loading head", "error", err)
@@ -74,7 +73,7 @@ templates.WritePageTemplate(w, gitList)
}
func (g *GitHandler) Refs(w http.ResponseWriter, r *http.Request) {
- name := mux.Vars(r)["name"]
+ name := r.PathValue("name")
tags, err := g.gitService.ListTags(name)
if err != nil {
@@ -106,8 +105,8 @@ templates.WritePageTemplate(w, gitList)
}
func (g *GitHandler) Tree(w http.ResponseWriter, r *http.Request) {
- name := mux.Vars(r)["name"]
- ref := mux.Vars(r)["ref"]
+ name := r.PathValue("name")
+ ref := r.PathValue("ref")
gitList := &templates.GitItemPage{
Name: name,
Ref: ref,
@@ -117,8 +116,8 @@ templates.WritePageTemplate(w, gitList)
}
func (g *GitHandler) Log(w http.ResponseWriter, r *http.Request) {
- name := mux.Vars(r)["name"]
- ref := mux.Vars(r)["ref"]
+ name := r.PathValue("name")
+ ref := r.PathValue("ref")
commits, err := g.gitService.ListCommits(name, ref)
if err != nil {
diff --git a/pkg/handler/router.go b/pkg/handler/router.go
index 79f70f11e263dbac66bf9660a97a4514b0dfd5fb..bdf883ed8a8af090669e285504118bda8d86450a 100644
--- a/pkg/handler/router.go
+++ b/pkg/handler/router.go
@@ -9,7 +9,6 @@ "git.gabrielgio.me/cerrado/pkg/handler/config"
"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
@@ -25,17 +24,17 @@ aboutHandler = about.NewAboutHandler(configRepo)
configHander = config.ConfigFile(configRepo)
)
- staticHandler, err := static.NewStaticHander("/static/")
+ staticHandler, err := static.ServeStaticHandler()
if err != nil {
return nil, err
}
- mux := mux.NewRouter()
+ mux := http.NewServeMux()
- mux.PathPrefix("/static").Handler(staticHandler)
- mux.HandleFunc("/{name}/about", gitHandler.About)
+ 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}/refs/{$}", gitHandler.Refs)
mux.HandleFunc("/{name}/tree/{ref}", gitHandler.Tree)
mux.HandleFunc("/{name}/log/{ref}", gitHandler.Log)
mux.HandleFunc("/config", configHander)
diff --git a/pkg/handler/static/handler.go b/pkg/handler/static/handler.go
index 6a826cc988aa4d11f5f71417b4a3198a7d611882..a8b458324580082c2424b21a65d92c2849e6a836 100644
--- a/pkg/handler/static/handler.go
+++ b/pkg/handler/static/handler.go
@@ -7,12 +7,15 @@
"git.gabrielgio.me/cerrado/static"
)
-func NewStaticHander(prefix string) (http.Handler, error) {
+func ServeStaticHandler() (func(w http.ResponseWriter, r *http.Request), error) {
staticFs, err := fs.Sub(static.Static, ".")
if err != nil {
return nil, err
}
- handler := http.StripPrefix(prefix, http.FileServer(http.FS(staticFs)))
- return handler, nil
+ return func(w http.ResponseWriter, r *http.Request) {
+ f := r.PathValue("file")
+
+ http.ServeFileFS(w, r, staticFs, f)
+ }, nil
}