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/config" 9 "github.com/icyphox/bild/db" 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.Route("/repo", func(r chi.Router) { 21 // r.Use(h.AuthMiddleware) 22 // r.Get("/new", h.NewRepo) 23 // r.Put("/new", h.NewRepo) 24 // }) 25 26 r.Get("/", h.Index) 27 r.Route("/{did}", func(r chi.Router) { 28 // Repo routes 29 r.Route("/{name}", func(r chi.Router) { 30 r.Get("/", h.RepoIndex) 31 r.Get("/info/refs", h.InfoRefs) 32 r.Post("/git-upload-pack", h.UploadPack) 33 34 r.Route("/tree/{ref}", func(r chi.Router) { 35 r.Get("/*", h.RepoTree) 36 }) 37 38 r.Route("/blob/{ref}", func(r chi.Router) { 39 r.Get("/*", h.FileContent) 40 }) 41 42 r.Get("/log/{ref}", h.Log) 43 r.Get("/archive/{file}", h.Archive) 44 r.Get("/commit/{ref}", h.Diff) 45 r.Get("/refs/", h.Refs) 46 }) 47 }) 48 49 return r, nil 50} 51 52type Handle struct { 53 c *config.Config 54 db *db.DB 55} 56 57func (h *Handle) Multiplex(w http.ResponseWriter, r *http.Request) { 58 path := chi.URLParam(r, "*") 59 60 if r.URL.RawQuery == "service=git-receive-pack" { 61 w.WriteHeader(http.StatusBadRequest) 62 w.Write([]byte("no pushing allowed!")) 63 return 64 } 65 66 fmt.Println(r.URL.RawQuery) 67 fmt.Println(r.Method) 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}