routes.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package v2
  2. import "github.com/gorilla/mux"
  3. // The following are definitions of the name under which all V2 routes are
  4. // registered. These symbols can be used to look up a route based on the name.
  5. const (
  6. RouteNameBase = "base"
  7. RouteNameManifest = "manifest"
  8. RouteNameTags = "tags"
  9. RouteNameBlob = "blob"
  10. RouteNameBlobUpload = "blob-upload"
  11. RouteNameBlobUploadChunk = "blob-upload-chunk"
  12. RouteNameCatalog = "catalog"
  13. )
  14. // Router builds a gorilla router with named routes for the various API
  15. // methods. This can be used directly by both server implementations and
  16. // clients.
  17. func Router() *mux.Router {
  18. return RouterWithPrefix("")
  19. }
  20. // RouterWithPrefix builds a gorilla router with a configured prefix
  21. // on all routes.
  22. func RouterWithPrefix(prefix string) *mux.Router {
  23. rootRouter := mux.NewRouter()
  24. router := rootRouter
  25. if prefix != "" {
  26. router = router.PathPrefix(prefix).Subrouter()
  27. }
  28. router.StrictSlash(true)
  29. for _, descriptor := range routeDescriptors {
  30. router.Path(descriptor.Path).Name(descriptor.Name)
  31. }
  32. return rootRouter
  33. }