diff --git a/app.go b/app.go index 76605f1b..b34a77de 100644 --- a/app.go +++ b/app.go @@ -4,6 +4,7 @@ import ( "fmt" "net/http" + "github.com/docker/docker-registry/api/urls" "github.com/docker/docker-registry/storagedriver" "github.com/docker/docker-registry/storagedriver/factory" @@ -35,18 +36,18 @@ type App struct { func NewApp(configuration configuration.Configuration) *App { app := &App{ Config: configuration, - router: v2APIRouter(), + router: urls.Router(), } // Register the handler dispatchers. - app.register(routeNameBase, func(ctx *Context, r *http.Request) http.Handler { + app.register(urls.RouteNameBase, func(ctx *Context, r *http.Request) http.Handler { return http.HandlerFunc(apiBase) }) - app.register(routeNameImageManifest, imageManifestDispatcher) - app.register(routeNameTags, tagsDispatcher) - app.register(routeNameBlob, layerDispatcher) - app.register(routeNameBlobUpload, layerUploadDispatcher) - app.register(routeNameBlobUploadResume, layerUploadDispatcher) + app.register(urls.RouteNameManifest, imageManifestDispatcher) + app.register(urls.RouteNameTags, tagsDispatcher) + app.register(urls.RouteNameBlob, layerDispatcher) + app.register(urls.RouteNameBlobUpload, layerUploadDispatcher) + app.register(urls.RouteNameBlobUploadChunk, layerUploadDispatcher) driver, err := factory.Create(configuration.Storage.Type(), configuration.Storage.Parameters()) diff --git a/app_test.go b/app_test.go index bb78044a..eb8ec597 100644 --- a/app_test.go +++ b/app_test.go @@ -6,6 +6,7 @@ import ( "net/url" "testing" + "github.com/docker/docker-registry/api/urls" "github.com/docker/docker-registry/configuration" ) @@ -16,10 +17,10 @@ import ( func TestAppDispatcher(t *testing.T) { app := &App{ Config: configuration.Configuration{}, - router: v2APIRouter(), + router: urls.Router(), } server := httptest.NewServer(app) - router := v2APIRouter() + router := urls.Router() serverURL, err := url.Parse(server.URL) if err != nil { @@ -71,33 +72,33 @@ func TestAppDispatcher(t *testing.T) { vars []string }{ { - endpoint: routeNameImageManifest, + endpoint: urls.RouteNameManifest, vars: []string{ "name", "foo/bar", "tag", "sometag", }, }, { - endpoint: routeNameTags, + endpoint: urls.RouteNameTags, vars: []string{ "name", "foo/bar", }, }, { - endpoint: routeNameBlob, + endpoint: urls.RouteNameBlob, vars: []string{ "name", "foo/bar", "digest", "tarsum.v1+bogus:abcdef0123456789", }, }, { - endpoint: routeNameBlobUpload, + endpoint: urls.RouteNameBlobUpload, vars: []string{ "name", "foo/bar", }, }, { - endpoint: routeNameBlobUploadResume, + endpoint: urls.RouteNameBlobUploadChunk, vars: []string{ "name", "foo/bar", "uuid", "theuuid", diff --git a/urls.go b/urls.go index 92233da4..4f294c95 100644 --- a/urls.go +++ b/urls.go @@ -4,6 +4,7 @@ import ( "net/http" "net/url" + "github.com/docker/docker-registry/api/urls" "github.com/docker/docker-registry/digest" "github.com/docker/docker-registry/storage" "github.com/gorilla/mux" @@ -17,7 +18,7 @@ type urlBuilder struct { func newURLBuilder(root *url.URL) *urlBuilder { return &urlBuilder{ url: root, - router: v2APIRouter(), + router: urls.Router(), } } @@ -40,7 +41,7 @@ func newURLBuilderFromString(root string) (*urlBuilder, error) { } func (ub *urlBuilder) buildBaseURL() (string, error) { - route := clonedRoute(ub.router, routeNameBase) + route := clonedRoute(ub.router, urls.RouteNameBase) baseURL, err := route. Schemes(ub.url.Scheme). @@ -54,7 +55,7 @@ func (ub *urlBuilder) buildBaseURL() (string, error) { } func (ub *urlBuilder) buildTagsURL(name string) (string, error) { - route := clonedRoute(ub.router, routeNameTags) + route := clonedRoute(ub.router, urls.RouteNameTags) tagsURL, err := route. Schemes(ub.url.Scheme). @@ -72,7 +73,7 @@ func (ub *urlBuilder) forManifest(m *storage.Manifest) (string, error) { } func (ub *urlBuilder) buildManifestURL(name, tag string) (string, error) { - route := clonedRoute(ub.router, routeNameImageManifest) + route := clonedRoute(ub.router, urls.RouteNameManifest) manifestURL, err := route. Schemes(ub.url.Scheme). @@ -90,7 +91,7 @@ func (ub *urlBuilder) forLayer(l storage.Layer) (string, error) { } func (ub *urlBuilder) buildLayerURL(name string, dgst digest.Digest) (string, error) { - route := clonedRoute(ub.router, routeNameBlob) + route := clonedRoute(ub.router, urls.RouteNameBlob) layerURL, err := route. Schemes(ub.url.Scheme). @@ -104,7 +105,7 @@ func (ub *urlBuilder) buildLayerURL(name string, dgst digest.Digest) (string, er } func (ub *urlBuilder) buildLayerUploadURL(name string) (string, error) { - route := clonedRoute(ub.router, routeNameBlobUpload) + route := clonedRoute(ub.router, urls.RouteNameBlobUpload) uploadURL, err := route. Schemes(ub.url.Scheme). @@ -122,7 +123,7 @@ func (ub *urlBuilder) forLayerUpload(layerUpload storage.LayerUpload) (string, e } func (ub *urlBuilder) buildLayerUploadResumeURL(name, uuid string, values ...url.Values) (string, error) { - route := clonedRoute(ub.router, routeNameBlobUploadResume) + route := clonedRoute(ub.router, urls.RouteNameBlobUploadChunk) uploadURL, err := route. Schemes(ub.url.Scheme).