MCPcopy
hub / github.com/google/go-containerregistry / NewTag

Function NewTag

pkg/name/tag.go:77–116  ·  view source on GitHub ↗

NewTag returns a new Tag representing the given name, according to the given strictness.

(name string, opts ...Option)

Source from the content-addressed store, hash-verified

75
76// NewTag returns a new Tag representing the given name, according to the given strictness.
77func NewTag(name string, opts ...Option) (Tag, error) {
78 opt := makeOptions(opts...)
79 base := name
80 tag := ""
81
82 // Split on ":"
83 parts := strings.Split(name, tagDelim)
84 // Verify that we aren't confusing a tag for a hostname w/ port for the purposes of weak validation.
85 if len(parts) > 1 && !strings.Contains(parts[len(parts)-1], regRepoDelimiter) {
86 base = strings.Join(parts[:len(parts)-1], tagDelim)
87 tag = parts[len(parts)-1]
88 if tag == "" {
89 return Tag{}, newErrBadName("%s must specify a tag name after the colon", name)
90 }
91 }
92
93 // We don't require a tag, but if we get one check it's valid,
94 // even when not being strict.
95 // If we are being strict, we want to validate the tag regardless in case
96 // it's empty.
97 if tag != "" || opt.strict {
98 if err := checkTag(tag); err != nil {
99 return Tag{}, err
100 }
101 }
102
103 if tag == "" {
104 tag = opt.defaultTag
105 }
106
107 repo, err := NewRepository(base, opts...)
108 if err != nil {
109 return Tag{}, err
110 }
111 return Tag{
112 Repository: repo,
113 tag: tag,
114 original: name,
115 }, nil
116}
117
118// MarshalJSON formats the Tag into a string for JSON serialization.
119func (t Tag) MarshalJSON() ([]byte, error) { return json.Marshal(t.String()) }

Callers 15

TestPushAndPullContainerFunction · 0.92
TestWriteFunction · 0.92
TestMultiWriteSameImageFunction · 0.92
TestWriteForeignLayersFunction · 0.92
TestMultiWriteNoHistoryFunction · 0.92
TestUncompressedSizeFunction · 0.92
TestWriteSharedLayersFunction · 0.92
mainFunction · 0.92
mainFunction · 0.92

Calls 4

newErrBadNameFunction · 0.85
checkTagFunction · 0.85
NewRepositoryFunction · 0.85
makeOptionsFunction · 0.70

Tested by 15

TestPushAndPullContainerFunction · 0.74
TestWriteFunction · 0.74
TestMultiWriteSameImageFunction · 0.74
TestWriteForeignLayersFunction · 0.74
TestMultiWriteNoHistoryFunction · 0.74
TestUncompressedSizeFunction · 0.74
TestWriteSharedLayersFunction · 0.74
newReferenceFunction · 0.74
TestValidateFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…