validPortRegEx=regexp.MustCompile(`^([1-9]\d{0,3}|0|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$`)// adapted from https://stackoverflow.com/a/12968117
errEmptyRepo=errors.New("parsed repo was empty")
errTooManyColons=errors.New("ref may only contain a single colon character (:) unless specifying a port number")
validPortRegEx=regexp.MustCompile(`^([1-9]\d{0,3}|0|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$`)// adapted from https://stackoverflow.com/a/12968117
// TODO: Currently we don't support digests, so we are only splitting on the
// colon. However, when we add support for digests, we'll need to use the
// regexp anyway to split on both colons and @, so leaving it like this for
// now
referenceDelimiter=regexp.MustCompile(`[:]`)
errEmptyRepo=errors.New("parsed repo was empty")
errTooManyColons=errors.New("ref may only contain a single colon character (:) unless specifying a port number")
)
type(
// Reference defines the main components of a reference specification
Referencestruct{
*reference.Spec
Tagstring
Repostring
}
@ -42,22 +45,34 @@ type (
// ParseReference converts a string to a Reference
funcParseReference(sstring)(*Reference,error){
spec,err:=reference.Parse(s)
iferr!=nil{
returnnil,err
ifs==""{
returnnil,errEmptyRepo
}
// Split the components of the string on the colon or @, if it is more than 3,
// immediately return an error. Other validation will be performed later in
// the function
splitComponents:=referenceDelimiter.Split(s,-1)
iflen(splitComponents)>3{
returnnil,errTooManyColons
}
// convert to our custom type and make necessary mods