Parse parses s and returns a syntactically valid Reference. If an error was encountered it is returned, along with a nil Reference. NOTE: Parse will not handle short digests.
(s string)
| 187 | // If an error was encountered it is returned, along with a nil Reference. |
| 188 | // NOTE: Parse will not handle short digests. |
| 189 | func Parse(s string) (Reference, error) { |
| 190 | matches := ReferenceRegexp.FindStringSubmatch(s) |
| 191 | if matches == nil { |
| 192 | if s == "" { |
| 193 | return nil, ErrNameEmpty |
| 194 | } |
| 195 | if ReferenceRegexp.FindStringSubmatch(strings.ToLower(s)) != nil { |
| 196 | return nil, ErrNameContainsUppercase |
| 197 | } |
| 198 | return nil, ErrReferenceInvalidFormat |
| 199 | } |
| 200 | |
| 201 | if len(matches[1]) > NameTotalLengthMax { |
| 202 | return nil, ErrNameTooLong |
| 203 | } |
| 204 | |
| 205 | var repo repository |
| 206 | |
| 207 | nameMatch := anchoredNameRegexp.FindStringSubmatch(matches[1]) |
| 208 | if len(nameMatch) == 3 { |
| 209 | repo.domain = nameMatch[1] |
| 210 | repo.path = nameMatch[2] |
| 211 | } else { |
| 212 | repo.domain = "" |
| 213 | repo.path = matches[1] |
| 214 | } |
| 215 | |
| 216 | ref := reference{ |
| 217 | namedRepository: repo, |
| 218 | tag: matches[2], |
| 219 | } |
| 220 | if matches[3] != "" { |
| 221 | var err error |
| 222 | ref.digest, err = digest.Parse(matches[3]) |
| 223 | if err != nil { |
| 224 | return nil, err |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | r := getBestReferenceType(ref) |
| 229 | if r == nil { |
| 230 | return nil, ErrNameEmpty |
| 231 | } |
| 232 | |
| 233 | return r, nil |
| 234 | } |
| 235 | |
| 236 | // ParseNamed parses s and returns a syntactically valid reference implementing |
| 237 | // the Named interface. The reference must have a name and be in the canonical |
searching dependent graphs…