@@ -3,40 +3,55 @@ package layout
3
3
import v1 "github.com/google/go-containerregistry/pkg/v1"
4
4
5
5
// Option is a functional option for Layout.
6
- //
7
- // TODO: We'll need to change this signature to support Sparse/Thin images.
8
- // Or, alternatively, wrap it in a sparse.Image that returns an empty list for layers?
9
- type Option func (* v1.Descriptor ) error
6
+ type Option func (* options )
7
+
8
+ type options struct {
9
+ descOpts []descriptorOption
10
+ }
11
+
12
+ func makeOptions (opts ... Option ) * options {
13
+ o := & options {
14
+ descOpts : []descriptorOption {},
15
+ }
16
+ for _ , apply := range opts {
17
+ apply (o )
18
+ }
19
+ return o
20
+ }
21
+
22
+ type descriptorOption func (* v1.Descriptor )
10
23
11
24
// WithAnnotations adds annotations to the artifact descriptor.
12
25
func WithAnnotations (annotations map [string ]string ) Option {
13
- return func (desc * v1. Descriptor ) error {
14
- if desc . Annotations == nil {
15
- desc .Annotations = make ( map [ string ] string )
16
- }
17
- for k , v := range annotations {
18
- desc . Annotations [ k ] = v
19
- }
20
-
21
- return nil
26
+ return func (o * options ) {
27
+ o . descOpts = append ( o . descOpts , func ( desc * v1. Descriptor ) {
28
+ if desc .Annotations == nil {
29
+ desc . Annotations = make ( map [ string ] string )
30
+ }
31
+ for k , v := range annotations {
32
+ desc . Annotations [ k ] = v
33
+ }
34
+ })
22
35
}
23
36
}
24
37
25
38
// WithURLs adds urls to the artifact descriptor.
26
39
func WithURLs (urls []string ) Option {
27
- return func (desc * v1.Descriptor ) error {
28
- if desc .URLs == nil {
29
- desc .URLs = []string {}
30
- }
31
- desc .URLs = append (desc .URLs , urls ... )
32
- return nil
40
+ return func (o * options ) {
41
+ o .descOpts = append (o .descOpts , func (desc * v1.Descriptor ) {
42
+ if desc .URLs == nil {
43
+ desc .URLs = []string {}
44
+ }
45
+ desc .URLs = append (desc .URLs , urls ... )
46
+ })
33
47
}
34
48
}
35
49
36
50
// WithPlatform sets the platform of the artifact descriptor.
37
51
func WithPlatform (platform v1.Platform ) Option {
38
- return func (desc * v1.Descriptor ) error {
39
- desc .Platform = & platform
40
- return nil
52
+ return func (o * options ) {
53
+ o .descOpts = append (o .descOpts , func (desc * v1.Descriptor ) {
54
+ desc .Platform = & platform
55
+ })
41
56
}
42
57
}
0 commit comments