...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package layout
16
17 import v1 "github.com/google/go-containerregistry/pkg/v1"
18
19
20 type Option func(*options)
21
22 type options struct {
23 descOpts []descriptorOption
24 }
25
26 func makeOptions(opts ...Option) *options {
27 o := &options{
28 descOpts: []descriptorOption{},
29 }
30 for _, apply := range opts {
31 apply(o)
32 }
33 return o
34 }
35
36 type descriptorOption func(*v1.Descriptor)
37
38
39 func WithAnnotations(annotations map[string]string) Option {
40 return func(o *options) {
41 o.descOpts = append(o.descOpts, func(desc *v1.Descriptor) {
42 if desc.Annotations == nil {
43 desc.Annotations = make(map[string]string)
44 }
45 for k, v := range annotations {
46 desc.Annotations[k] = v
47 }
48 })
49 }
50 }
51
52
53 func WithURLs(urls []string) Option {
54 return func(o *options) {
55 o.descOpts = append(o.descOpts, func(desc *v1.Descriptor) {
56 if desc.URLs == nil {
57 desc.URLs = []string{}
58 }
59 desc.URLs = append(desc.URLs, urls...)
60 })
61 }
62 }
63
64
65 func WithPlatform(platform v1.Platform) Option {
66 return func(o *options) {
67 o.descOpts = append(o.descOpts, func(desc *v1.Descriptor) {
68 desc.Platform = &platform
69 })
70 }
71 }
72
View as plain text