Debian Codegraph @

registry/example_reference_test.go

raw
1 /*
2 Copyright The ORAS Authors.
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 */
15
16 package registry_test
17
18 import (
19 _ "crypto/sha256" // required to parse sha256 digest. See [Reference.Digest]
20 "fmt"
21
22 "oras.land/oras-go/v2/registry"
23 )
24
25 // ExampleParseReference_digest demonstrates parsing a reference string with
26 // digest and print its components.
27 func ExampleParseReference_digest() {
28 rawRef := "ghcr.io/oras-project/oras-go@sha256:601d05a48832e7946dab8f49b14953549bebf42e42f4d7973b1a5a287d77ab76"
29 ref, err := registry.ParseReference(rawRef)
30 if err != nil {
31 panic(err)
32 }
33
34 fmt.Println("Registry:", ref.Registry)
35 fmt.Println("Repository:", ref.Repository)
36
37 digest, err := ref.Digest()
38 if err != nil {
39 panic(err)
40 }
41 fmt.Println("Digest:", digest)
42
43 // Output:
44 // Registry: ghcr.io
45 // Repository: oras-project/oras-go
46 // Digest: sha256:601d05a48832e7946dab8f49b14953549bebf42e42f4d7973b1a5a287d77ab76
47 }