mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00

This moves the types for the `engine-api` repo to the existing types package. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
34 lines
921 B
Go
34 lines
921 B
Go
package reference
|
|
|
|
import (
|
|
distreference "github.com/docker/distribution/reference"
|
|
)
|
|
|
|
// Parse parses the given references and returns the repository and
|
|
// tag (if present) from it. If there is an error during parsing, it will
|
|
// return an error.
|
|
func Parse(ref string) (string, string, error) {
|
|
distributionRef, err := distreference.ParseNamed(ref)
|
|
if err != nil {
|
|
return "", "", err
|
|
}
|
|
|
|
tag := GetTagFromNamedRef(distributionRef)
|
|
return distributionRef.Name(), tag, nil
|
|
}
|
|
|
|
// GetTagFromNamedRef returns a tag from the specified reference.
|
|
// This function is necessary as long as the docker "server" api makes the distinction between repository
|
|
// and tags.
|
|
func GetTagFromNamedRef(ref distreference.Named) string {
|
|
var tag string
|
|
switch x := ref.(type) {
|
|
case distreference.Digested:
|
|
tag = x.Digest().String()
|
|
case distreference.NamedTagged:
|
|
tag = x.Tag()
|
|
default:
|
|
tag = "latest"
|
|
}
|
|
return tag
|
|
}
|