Use reference package internally

Most places in the registry were using string types to refer to
repository names. This changes them to use reference.Named, so the type
system can enforce validation of the naming rules.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
This commit is contained in:
Aaron Lehmann
2015-12-15 14:35:23 -08:00
parent caa2001e1f
commit 4441333912
35 changed files with 323 additions and 246 deletions

View File

@@ -107,18 +107,11 @@ func (reg *registry) Scope() distribution.Scope {
// Repository returns an instance of the repository tied to the registry.
// Instances should not be shared between goroutines but are cheap to
// allocate. In general, they should be request scoped.
func (reg *registry) Repository(ctx context.Context, canonicalName string) (distribution.Repository, error) {
if _, err := reference.ParseNamed(canonicalName); err != nil {
return nil, distribution.ErrRepositoryNameInvalid{
Name: canonicalName,
Reason: err,
}
}
func (reg *registry) Repository(ctx context.Context, canonicalName reference.Named) (distribution.Repository, error) {
var descriptorCache distribution.BlobDescriptorService
if reg.blobDescriptorCacheProvider != nil {
var err error
descriptorCache, err = reg.blobDescriptorCacheProvider.RepositoryScoped(canonicalName)
descriptorCache, err = reg.blobDescriptorCacheProvider.RepositoryScoped(canonicalName.Name())
if err != nil {
return nil, err
}
@@ -136,12 +129,12 @@ func (reg *registry) Repository(ctx context.Context, canonicalName string) (dist
type repository struct {
*registry
ctx context.Context
name string
name reference.Named
descriptorCache distribution.BlobDescriptorService
}
// Name returns the name of the repository.
func (repo *repository) Name() string {
func (repo *repository) Name() reference.Named {
return repo.name
}