forked from regclient/regclient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
48 lines (45 loc) · 1.19 KB
/
Copy pathexample_test.go
File metadata and controls
48 lines (45 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package regclient_test
import (
"context"
"fmt"
"github.com/regclient/regclient"
"github.com/regclient/regclient/config"
"github.com/regclient/regclient/types/ref"
)
func ExampleNew() {
ctx := context.Background()
// use config.Host to provide registry logins, TLS, and other registry settings
exHostLocal := config.Host{
Name: "registry.example.org:5000",
TLS: config.TLSDisabled,
User: "exUser",
Pass: "exPass",
}
exHostDH := config.Host{
Name: "docker.io",
User: "dhUser",
Pass: "dhPass",
}
// define a regclient with desired options
rc := regclient.New(
regclient.WithConfigHosts([]config.Host{exHostLocal, exHostDH}),
regclient.WithDockerCerts(),
regclient.WithDockerCreds(),
regclient.WithUserAgent("regclient/example"),
)
// create a reference for an image
r, err := ref.New("ghcr.io/regclient/regctl:latest")
if err != nil {
fmt.Printf("failed to create ref: %v\n", err)
return
}
defer rc.Close(ctx, r)
// get a manifest (or call other regclient methods)
m, err := rc.ManifestGet(ctx, r)
if err != nil {
fmt.Printf("failed to get manifest: %v\n", err)
return
}
fmt.Println(m.GetDescriptor().MediaType)
// Output: application/vnd.oci.image.index.v1+json
}