Parse parses the string into a structured ref.
(s string)
| 84 | |
| 85 | // Parse parses the string into a structured ref. |
| 86 | func Parse(s string) (Spec, error) { |
| 87 | if strings.Contains(s, "://") { |
| 88 | return Spec{}, ErrInvalid |
| 89 | } |
| 90 | |
| 91 | u, err := url.Parse("dummy://" + s) |
| 92 | if err != nil { |
| 93 | return Spec{}, err |
| 94 | } |
| 95 | |
| 96 | if u.Scheme != "dummy" { |
| 97 | return Spec{}, ErrInvalid |
| 98 | } |
| 99 | |
| 100 | if u.Host == "" { |
| 101 | return Spec{}, ErrHostnameRequired |
| 102 | } |
| 103 | |
| 104 | var object string |
| 105 | |
| 106 | if idx := splitRe.FindStringIndex(u.Path); idx != nil { |
| 107 | // This allows us to retain the @ to signify digests or shortened digests in |
| 108 | // the object. |
| 109 | object = u.Path[idx[0]:] |
| 110 | if object[:1] == ":" { |
| 111 | object = object[1:] |
| 112 | } |
| 113 | u.Path = u.Path[:idx[0]] |
| 114 | } |
| 115 | |
| 116 | return Spec{ |
| 117 | Locator: path.Join(u.Host, u.Path), |
| 118 | Object: object, |
| 119 | }, nil |
| 120 | } |
| 121 | |
| 122 | // Hostname returns the hostname portion of the locator. |
| 123 | // |
searching dependent graphs…