github.com/mika/distribution@v2.2.2-0.20160108133430-a75790e3d8e0+incompatible/registry/api/v2/routes.go (about) 1 package v2 2 3 import "github.com/gorilla/mux" 4 5 // The following are definitions of the name under which all V2 routes are 6 // registered. These symbols can be used to look up a route based on the name. 7 const ( 8 RouteNameBase = "base" 9 RouteNameManifest = "manifest" 10 RouteNameTags = "tags" 11 RouteNameBlob = "blob" 12 RouteNameBlobUpload = "blob-upload" 13 RouteNameBlobUploadChunk = "blob-upload-chunk" 14 RouteNameCatalog = "catalog" 15 ) 16 17 var allEndpoints = []string{ 18 RouteNameManifest, 19 RouteNameCatalog, 20 RouteNameTags, 21 RouteNameBlob, 22 RouteNameBlobUpload, 23 RouteNameBlobUploadChunk, 24 } 25 26 // Router builds a gorilla router with named routes for the various API 27 // methods. This can be used directly by both server implementations and 28 // clients. 29 func Router() *mux.Router { 30 return RouterWithPrefix("") 31 } 32 33 // RouterWithPrefix builds a gorilla router with a configured prefix 34 // on all routes. 35 func RouterWithPrefix(prefix string) *mux.Router { 36 rootRouter := mux.NewRouter() 37 router := rootRouter 38 if prefix != "" { 39 router = router.PathPrefix(prefix).Subrouter() 40 } 41 42 router.StrictSlash(true) 43 44 for _, descriptor := range routeDescriptors { 45 router.Path(descriptor.Path).Name(descriptor.Name) 46 } 47 48 return rootRouter 49 }