Permalink
Browse files

[ADD] Add support for multiple repositories in a folder

  • Loading branch information...
ruiztulio committed Jan 25, 2019
1 parent a87d968 commit 42c51ba2724e42cf79ae6652aa2d6d56b79c6d15
Showing with 28 additions and 4 deletions.
  1. +5 −3 handlers.go
  2. +23 −1 mux.go
@@ -90,11 +90,13 @@ func join(base string, names ...string) (string, error) {

// getRepo returns the repository location, relative to s.Path.
func (s *Server) getRepo(r *http.Request) string {
repo := "."
if strings.HasPrefix(fmt.Sprintf("%s", middleware.Pattern(r.Context())), "/:repo") {
return pat.Param(r, "repo")
repo = pat.Param(r, "repo")
} else if strings.HasPrefix(fmt.Sprintf("%s", middleware.Pattern(r.Context())), "/:folder/:repo") {
repo, _ = join(pat.Param(r, "folder"), pat.Param(r, "repo"))
}

return "."
return repo
}

// getPath returns the path for a file type in the repo.
24 mux.go
@@ -47,25 +47,47 @@ func NewHandler(server Server) *goji.Mux {

mux.HandleFunc(pat.Head("/config"), server.CheckConfig)
mux.HandleFunc(pat.Head("/:repo/config"), server.CheckConfig)
mux.HandleFunc(pat.Head("/*/:repo/config"), server.CheckConfig)

mux.HandleFunc(pat.Get("/config"), server.GetConfig)
mux.HandleFunc(pat.Get("/:repo/config"), server.GetConfig)
mux.HandleFunc(pat.Get("/:folder/:repo/config"), server.GetConfig)

mux.HandleFunc(pat.Post("/config"), server.SaveConfig)
mux.HandleFunc(pat.Post("/:repo/config"), server.SaveConfig)
mux.HandleFunc(pat.Post("/:folder/:repo/config"), server.SaveConfig)

mux.HandleFunc(pat.Delete("/config"), server.DeleteConfig)
mux.HandleFunc(pat.Delete("/:repo/config"), server.DeleteConfig)
mux.HandleFunc(pat.Delete("/:folder/:repo/config"), server.DeleteConfig)

mux.HandleFunc(pat.Get("/:type/"), server.ListBlobs)
mux.HandleFunc(pat.Get("/:repo/:type/"), server.ListBlobs)
mux.HandleFunc(pat.Get("/:folder/:repo/:type/"), server.ListBlobs)

mux.HandleFunc(pat.Head("/:type/:name"), server.CheckBlob)
mux.HandleFunc(pat.Head("/:repo/:type/:name"), server.CheckBlob)
mux.HandleFunc(pat.Head("/:folder/:type/:name"), server.CheckBlob)
mux.HandleFunc(pat.Head("/:folder/:repo/:type/:name"), server.CheckBlob)

mux.HandleFunc(pat.Get("/:type/:name"), server.GetBlob)
mux.HandleFunc(pat.Get("/:repo/:type/:name"), server.GetBlob)
mux.HandleFunc(pat.Get("/:folder/:type/:name"), server.GetBlob)
mux.HandleFunc(pat.Get("/:folder/:repo/:type/:name"), server.GetBlob)

mux.HandleFunc(pat.Post("/:type/:name"), server.SaveBlob)
mux.HandleFunc(pat.Post("/:repo/:type/:name"), server.SaveBlob)
mux.HandleFunc(pat.Post("/:folder/:repo/:type/:name"), server.SaveBlob)

mux.HandleFunc(pat.Delete("/:type/:name"), server.DeleteBlob)
mux.HandleFunc(pat.Delete("/:repo/:type/:name"), server.DeleteBlob)
mux.HandleFunc(pat.Delete("/:folder/:type/:name"), server.DeleteBlob)
mux.HandleFunc(pat.Delete("/:folder/:repo/:type/:name"), server.DeleteBlob)

mux.HandleFunc(pat.Post("/"), server.CreateRepo)
mux.HandleFunc(pat.Post("/:repo"), server.CreateRepo)
mux.HandleFunc(pat.Post("/:repo/"), server.CreateRepo)

mux.HandleFunc(pat.Post("/:folder/:repo/"), server.CreateRepo)

return mux
}

0 comments on commit 42c51ba

Please sign in to comment.