forked from TrueCloudLab/distribution
Merge pull request #2062 from nishanttotla/with-default-tag
Adding utility functions - IsNameOnly and EnsureTagged
This commit is contained in:
commit
d22e09a668
2 changed files with 34 additions and 0 deletions
12
reference/helpers.go
Normal file
12
reference/helpers.go
Normal file
|
@ -0,0 +1,12 @@
|
|||
package reference
|
||||
|
||||
// IsNameOnly returns true if reference only contains a repo name.
|
||||
func IsNameOnly(ref Named) bool {
|
||||
if _, ok := ref.(NamedTagged); ok {
|
||||
return false
|
||||
}
|
||||
if _, ok := ref.(Canonical); ok {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
22
reference/normalize.go
Normal file
22
reference/normalize.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
package reference
|
||||
|
||||
var (
|
||||
defaultTag = "latest"
|
||||
)
|
||||
|
||||
// EnsureTagged adds the default tag "latest" to a reference if it only has
|
||||
// a repo name.
|
||||
func EnsureTagged(ref Named) NamedTagged {
|
||||
namedTagged, ok := ref.(NamedTagged)
|
||||
if !ok {
|
||||
namedTagged, err := WithTag(ref, defaultTag)
|
||||
if err != nil {
|
||||
// Default tag must be valid, to create a NamedTagged
|
||||
// type with non-validated input the WithTag function
|
||||
// should be used instead
|
||||
panic(err)
|
||||
}
|
||||
return namedTagged
|
||||
}
|
||||
return namedTagged
|
||||
}
|
Loading…
Reference in a new issue