MCPcopy
hub / github.com/containerd/containerd / Parse

Function Parse

pkg/reference/reference.go:86–120  ·  view source on GitHub ↗

Parse parses the string into a structured ref.

(s string)

Source from the content-addressed store, hash-verified

84
85// Parse parses the string into a structured ref.
86func 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//

Callers 3

resolveDockerBaseMethod · 0.92
TestReferenceParserFunction · 0.70

Calls 1

FindStringIndexMethod · 0.80

Tested by 1

TestReferenceParserFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…