routes/handler.go (view raw)
1package routes
2
3import (
4 "net/http"
5
6 "github.com/alexedwards/flow"
7 "icyphox.sh/legit/config"
8)
9
10func Handlers(c *config.Config) *flow.Mux {
11 mux := flow.New()
12 d := deps{c}
13
14 mux.NotFound = http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
15 d.Write404(w)
16 })
17
18 mux.HandleFunc("/", d.Index, "GET")
19 mux.HandleFunc("/:name", d.RepoIndex, "GET")
20 mux.HandleFunc("/:name/tree/:ref/...", d.RepoTree, "GET")
21 mux.HandleFunc("/:name/blob/:ref/...", d.FileContent, "GET")
22 mux.HandleFunc("/:name/log/:ref", d.Log, "GET")
23 mux.HandleFunc("/:name/commit/:ref", d.Diff, "GET")
24 return mux
25}