Skip to content

Commit 57ce09b

Browse files
committed
pkg/reference: SplitObject: add proper GoDoc
The behavior of this function is quite counter-intuitive, as it preserves the delimiter in the result. This function should probably have been an internal function, as its use for external consumers would be very limited, but let's at least document the (surprising) behavior for those that are considering to use it. It appears that BuildKit is currently the only (publicly visible) external consumer of this function; I am planning to inline its functionality in Spec.Digest() and to deprecate this function so that it can be removed. Signed-off-by: Sebastiaan van Stijn <[email protected]> (cherry picked from commit 4214595) Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 78ac93f commit 57ce09b

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

reference/reference.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,19 @@ func (r Spec) String() string {
151151
return r.Locator + ":" + r.Object
152152
}
153153

154-
// SplitObject provides two parts of the object spec, delimited by an `@`
155-
// symbol.
154+
// SplitObject provides two parts of the object spec, delimited by an "@"
155+
// symbol. It does not perform any validation on correctness of the values
156+
// returned, and it's the callers' responsibility to validate the result.
156157
//
157-
// Either may be empty and it is the callers job to validate them
158-
// appropriately.
158+
// If an "@" delimiter is found, it returns the part *including* the "@"
159+
// delimiter as "tag", and the part after the "@" as digest.
160+
//
161+
// The example below produces "docker.io/library/ubuntu:latest@" and
162+
// "sha256:deadbeef";
163+
//
164+
// t, d := SplitObject("docker.io/library/ubuntu:latest@sha256:deadbeef")
165+
// fmt.Println(t) // docker.io/library/ubuntu:latest@
166+
// fmt.Println(d) // sha256:deadbeef
159167
func SplitObject(obj string) (tag string, dgst digest.Digest) {
160168
if i := strings.Index(obj, "@"); i >= 0 {
161169
// Offset by one so preserve the "@" in the tag returned.

0 commit comments

Comments
 (0)