@@ -3,40 +3,55 @@ package layout
33import v1 "github.com/google/go-containerregistry/pkg/v1"
44
55// 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 )
1023
1124// WithAnnotations adds annotations to the artifact descriptor.
1225func 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+ })
2235 }
2336}
2437
2538// WithURLs adds urls to the artifact descriptor.
2639func 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+ })
3347 }
3448}
3549
3650// WithPlatform sets the platform of the artifact descriptor.
3751func 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+ })
4156 }
4257}
0 commit comments