all repos — elgit @ cd22584c7477f796f69c32a6259e174e2d0ae145

fork of legit: web frontend for git, written in go

routes: switch to net/http router BREAKING: This commit reworks routes.Handlers (and everywhere else) to use http.ServeMux -- and subsequently, Go 1.22's new net/http router. This might break something.

commit

cd22584c7477f796f69c32a6259e174e2d0ae145

parent

a87f88a57c68627a1f63f1551fcef2c1f1ec7036

1 file changed, 13 insertions(+), 19 deletions(-)

changed files
M routes/routes.goroutes/routes.go
@@ -13,7 +13,6 @@ "time"
"git.icyphox.sh/legit/config" "git.icyphox.sh/legit/git" - "github.com/alexedwards/flow" "github.com/dustin/go-humanize" "github.com/microcosm-cc/bluemonday" "github.com/russross/blackfriday/v2"
@@ -85,7 +84,7 @@ }
} func (d *deps) RepoIndex(w http.ResponseWriter, r *http.Request) { - name := flow.Param(r.Context(), "name") + name := r.PathValue("name") if d.isIgnored(name) { d.Write404(w) return
@@ -165,13 +164,13 @@ return
} func (d *deps) RepoTree(w http.ResponseWriter, r *http.Request) { - name := flow.Param(r.Context(), "name") + name := r.PathValue("name") if d.isIgnored(name) { d.Write404(w) return } - treePath := flow.Param(r.Context(), "...") - ref := flow.Param(r.Context(), "ref") + treePath := r.PathValue("rest") + ref := r.PathValue("ref") name = filepath.Clean(name) path := filepath.Join(d.c.Repo.ScanPath, name)
@@ -200,18 +199,13 @@ return
} func (d *deps) FileContent(w http.ResponseWriter, r *http.Request) { - var raw bool - if rawParam, err := strconv.ParseBool(r.URL.Query().Get("raw")); err == nil { - raw = rawParam - } - - name := flow.Param(r.Context(), "name") + name := r.PathValue("name") if d.isIgnored(name) { d.Write404(w) return } - treePath := flow.Param(r.Context(), "...") - ref := flow.Param(r.Context(), "ref") + treePath := r.PathValue("rest") + ref := r.PathValue("ref") name = filepath.Clean(name) path := filepath.Join(d.c.Repo.ScanPath, name)
@@ -237,12 +231,12 @@ return
} func (d *deps) Log(w http.ResponseWriter, r *http.Request) { - name := flow.Param(r.Context(), "name") + name := r.PathValue("name") if d.isIgnored(name) { d.Write404(w) return } - ref := flow.Param(r.Context(), "ref") + ref := r.PathValue("ref") path := filepath.Join(d.c.Repo.ScanPath, name) gr, err := git.Open(path, ref)
@@ -276,12 +270,12 @@ }
} func (d *deps) Diff(w http.ResponseWriter, r *http.Request) { - name := flow.Param(r.Context(), "name") + name := r.PathValue("name") if d.isIgnored(name) { d.Write404(w) return } - ref := flow.Param(r.Context(), "ref") + ref := r.PathValue("ref") path := filepath.Join(d.c.Repo.ScanPath, name) gr, err := git.Open(path, ref)
@@ -317,7 +311,7 @@ }
} func (d *deps) Refs(w http.ResponseWriter, r *http.Request) { - name := flow.Param(r.Context(), "name") + name := r.PathValue("name") if d.isIgnored(name) { d.Write404(w) return
@@ -361,7 +355,7 @@ }
} func (d *deps) ServeStatic(w http.ResponseWriter, r *http.Request) { - f := flow.Param(r.Context(), "file") + f := r.PathValue("file") f = filepath.Clean(filepath.Join(d.c.Dirs.Static, f)) http.ServeFile(w, r, f)