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.Group(func(r chi.Router) { 21 // r.Route("/settings", func(r chi.Router) { 22 // r.Get("/keys", h.Keys) 23 // r.Put("/keys", h.Keys) 24 // }) 25 // }) 26 27 r.Get("/", h.Index) 28 r.Route("/{did}", func(r chi.Router) { 29 // Repo routes 30 r.Route("/{name}", func(r chi.Router) { 31 r.Get("/", h.RepoIndex) 32 r.Get("/info/refs", h.InfoRefs) 33 r.Post("/git-upload-pack", h.UploadPack) 34 35 r.Route("/tree/{ref}", func(r chi.Router) { 36 r.Get("/*", h.RepoTree) 37 }) 38 39 r.Route("/blob/{ref}", func(r chi.Router) { 40 r.Get("/*", h.FileContent) 41 }) 42 43 r.Get("/log/{ref}", h.Log) 44 r.Get("/archive/{file}", h.Archive) 45 r.Get("/commit/{ref}", h.Diff) 46 r.Get("/refs/", h.Refs) 47 }) 48 }) 49 50 r.Route("/repo", func(r chi.Router) { 51 r.Put("/new", h.NewRepo) 52 }) 53 54 r.Route("/internal", func(r chi.Router) { 55 r.Use(h.VerifySignature) 56 r.Get("/health", h.Health) 57 }) 58 59 return r, nil 60} 61 62type Handle struct { 63 c *config.Config 64 db *db.DB 65} 66 67func (h *Handle) Multiplex(w http.ResponseWriter, r *http.Request) { 68 path := chi.URLParam(r, "*") 69 70 if r.URL.RawQuery == "service=git-receive-pack" { 71 w.WriteHeader(http.StatusBadRequest) 72 w.Write([]byte("no pushing allowed!")) 73 return 74 } 75 76 fmt.Println(r.URL.RawQuery) 77 fmt.Println(r.Method) 78 79 if path == "info/refs" && 80 r.URL.RawQuery == "service=git-upload-pack" && 81 r.Method == "GET" { 82 h.InfoRefs(w, r) 83 } else if path == "git-upload-pack" && r.Method == "POST" { 84 h.UploadPack(w, r) 85 } else if r.Method == "GET" { 86 h.RepoIndex(w, r) 87 } 88}