NewRepository returns a new Repository representing the given name, according to the given strictness.
(name string, opts ...Option)
| 77 | |
| 78 | // NewRepository returns a new Repository representing the given name, according to the given strictness. |
| 79 | func NewRepository(name string, opts ...Option) (Repository, error) { |
| 80 | opt := makeOptions(opts...) |
| 81 | if len(name) == 0 { |
| 82 | return Repository{}, newErrBadName("a repository name must be specified") |
| 83 | } |
| 84 | |
| 85 | var registry string |
| 86 | repo := name |
| 87 | parts := strings.SplitN(name, regRepoDelimiter, 2) |
| 88 | maybeRegistry := parts[0] |
| 89 | if len(parts) == 2 && (maybeRegistry == "localhost" || strings.ContainsAny(maybeRegistry, ".:")) { |
| 90 | // The first part of the repository is treated as the registry domain |
| 91 | // if it is localhost or contains a '.' or ':' character, otherwise it |
| 92 | // is all repository and the domain defaults to Docker Hub. |
| 93 | registry = maybeRegistry |
| 94 | repo = parts[1] |
| 95 | } |
| 96 | |
| 97 | if err := checkRepository(repo); err != nil { |
| 98 | return Repository{}, err |
| 99 | } |
| 100 | |
| 101 | reg, err := NewRegistry(registry, opts...) |
| 102 | if err != nil { |
| 103 | return Repository{}, err |
| 104 | } |
| 105 | if hasImplicitNamespace(repo, reg) && opt.strict { |
| 106 | return Repository{}, newErrBadName("strict validation requires the full repository path (missing 'library')") |
| 107 | } |
| 108 | return Repository{reg, repo}, nil |
| 109 | } |
| 110 | |
| 111 | // Tag returns a Tag in this Repository. |
| 112 | func (r Repository) Tag(identifier string) Tag { |
searching dependent graphs…