From cd22584c7477f796f69c32a6259e174e2d0ae145 Mon Sep 17 00:00:00 2001 From: Anirudh Oppiliappan Date: Wed, 27 Mar 2024 00:39:33 +0200 Subject: 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. --- routes/routes.go | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'routes/routes.go') diff --git a/routes/routes.go b/routes/routes.go index 2989752..18e3689 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -13,7 +13,6 @@ import ( "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) Index(w http.ResponseWriter, r *http.Request) { } 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 @@ func (d *deps) RepoIndex(w http.ResponseWriter, r *http.Request) { } 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 @@ func (d *deps) RepoTree(w http.ResponseWriter, r *http.Request) { } 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 @@ func (d *deps) FileContent(w http.ResponseWriter, r *http.Request) { } 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) Log(w http.ResponseWriter, r *http.Request) { } 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) Diff(w http.ResponseWriter, r *http.Request) { } 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) Refs(w http.ResponseWriter, r *http.Request) { } 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) -- cgit v1.2.3