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