aboutsummaryrefslogtreecommitdiff
path: root/routes
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--routes/git.go5
-rw-r--r--routes/handler.go31
-rw-r--r--routes/routes.go32
3 files changed, 29 insertions, 39 deletions
diff --git a/routes/git.go b/routes/git.go
index 1a5e035..b8877b9 100644
--- a/routes/git.go
+++ b/routes/git.go
@@ -6,7 +6,6 @@ import (
"net/http"
"path/filepath"
- "github.com/alexedwards/flow"
"github.com/go-git/go-billy/v5/osfs"
"github.com/go-git/go-git/v5/plumbing/format/pktline"
"github.com/go-git/go-git/v5/plumbing/protocol/packp"
@@ -15,7 +14,7 @@ import (
)
func (d *deps) InfoRefs(w http.ResponseWriter, r *http.Request) {
- name := flow.Param(r.Context(), "name")
+ name := r.PathValue("name")
name = filepath.Clean(name)
repo := filepath.Join(d.c.Repo.ScanPath, name)
@@ -61,7 +60,7 @@ func (d *deps) InfoRefs(w http.ResponseWriter, r *http.Request) {
}
func (d *deps) UploadPack(w http.ResponseWriter, r *http.Request) {
- name := flow.Param(r.Context(), "name")
+ name := r.PathValue("name")
name = filepath.Clean(name)
repo := filepath.Join(d.c.Repo.ScanPath, name)
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
}
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)