this repo has no description
1package knotserver 2 3import ( 4 "net/http" 5 6 "github.com/go-chi/chi" 7 "github.com/icyphox/bild/config" 8 "github.com/icyphox/bild/db" 9) 10 11func Setup(c *config.Config, db *db.DB) (http.Handler, error) { 12 r := chi.NewRouter() 13 14 h := Handle{ 15 c: c, 16 db: db, 17 } 18 19 // r.Route("/repo", func(r chi.Router) { 20 // r.Use(h.AuthMiddleware) 21 // r.Get("/new", h.NewRepo) 22 // r.Put("/new", h.NewRepo) 23 // }) 24 25 r.Route("/{did}", func(r chi.Router) { 26 r.Get("/", h.Index) 27 28 // Repo routes 29 r.Route("/{name}", func(r chi.Router) { 30 r.Get("/", h.Multiplex) 31 r.Post("/", h.Multiplex) 32 33 r.Route("/tree/{ref}", func(r chi.Router) { 34 r.Get("/*", h.RepoTree) 35 }) 36 37 r.Route("/blob/{ref}", func(r chi.Router) { 38 r.Get("/*", h.FileContent) 39 }) 40 41 r.Get("/log/{ref}", h.Log) 42 r.Get("/archive/{file}", h.Archive) 43 r.Get("/commit/{ref}", h.Diff) 44 r.Get("/refs/", h.Refs) 45 46 // Catch-all routes 47 r.Get("/*", h.Multiplex) 48 r.Post("/*", h.Multiplex) 49 }) 50 }) 51 52 return r, nil 53} 54 55type Handle struct { 56 c *config.Config 57 db *db.DB 58} 59 60func (h *Handle) Multiplex(w http.ResponseWriter, r *http.Request) { 61 path := chi.URLParam(r, "*") 62 63 if r.URL.RawQuery == "service=git-receive-pack" { 64 w.WriteHeader(http.StatusBadRequest) 65 w.Write([]byte("no pushing allowed!")) 66 return 67 } 68 69 if path == "info/refs" && 70 r.URL.RawQuery == "service=git-upload-pack" && 71 r.Method == "GET" { 72 h.InfoRefs(w, r) 73 } else if path == "git-upload-pack" && r.Method == "POST" { 74 h.UploadPack(w, r) 75 } else if r.Method == "GET" { 76 h.RepoIndex(w, r) 77 } 78}