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/handler.go | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'routes/handler.go') diff --git a/routes/handler.go b/routes/handler.go index a0e7832..bbe5e2c 100644 --- a/routes/handler.go +++ b/routes/handler.go @@ -4,13 +4,12 @@ import ( "net/http" "git.icyphox.sh/legit/config" - "github.com/alexedwards/flow" ) // Checks for gitprotocol-http(5) specific smells; if found, passes // the request on to the git http service, else render the web frontend. func (d *deps) Multiplex(w http.ResponseWriter, r *http.Request) { - path := flow.Param(r.Context(), "...") + path := r.PathValue("rest") if r.URL.RawQuery == "service=git-receive-pack" { w.WriteHeader(http.StatusBadRequest) @@ -29,23 +28,21 @@ func (d *deps) Multiplex(w http.ResponseWriter, r *http.Request) { } } -func Handlers(c *config.Config) *flow.Mux { - mux := flow.New() +func Handlers(c *config.Config) *http.ServeMux { + mux := http.NewServeMux() d := deps{c} - mux.NotFound = http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { - d.Write404(w) - }) - - mux.HandleFunc("/", d.Index, "GET") - mux.HandleFunc("/static/:file", d.ServeStatic, "GET") - mux.HandleFunc("/:name", d.Multiplex, "GET", "POST") - mux.HandleFunc("/:name/tree/:ref/...", d.RepoTree, "GET") - mux.HandleFunc("/:name/blob/:ref/...", d.FileContent, "GET") - mux.HandleFunc("/:name/log/:ref", d.Log, "GET") - mux.HandleFunc("/:name/commit/:ref", d.Diff, "GET") - mux.HandleFunc("/:name/refs", d.Refs, "GET") - mux.HandleFunc("/:name/...", d.Multiplex, "GET", "POST") + mux.HandleFunc("GET /", d.Index) + mux.HandleFunc("GET /static/{file}", d.ServeStatic) + mux.HandleFunc("GET /{name}", d.Multiplex) + mux.HandleFunc("POST /{name}", d.Multiplex) + mux.HandleFunc("GET /{name}/tree/{ref}/{rest...}", d.RepoTree) + mux.HandleFunc("GET /{name}/blob/{ref}/{rest...}", d.FileContent) + mux.HandleFunc("GET /{name}/log/{ref}", d.Log) + mux.HandleFunc("GET /{name}/commit/{ref}", d.Diff) + mux.HandleFunc("GET /{name}/refs/{$}", d.Refs) + mux.HandleFunc("GET /{name}/{rest...}", d.Multiplex) + mux.HandleFunc("POST /{name}/{rest...}", d.Multiplex) return mux } -- cgit v1.2.3