...

Source file src/github.com/google/go-containerregistry/pkg/v1/layout/options.go

Documentation: github.com/google/go-containerregistry/pkg/v1/layout

     1  // Copyright 2019 Google LLC All Rights Reserved.
     2  //
     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  package layout
    16  
    17  import v1 "github.com/google/go-containerregistry/pkg/v1"
    18  
    19  // Option is a functional option for Layout.
    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  // WithAnnotations adds annotations to the artifact descriptor.
    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  // WithURLs adds urls to the artifact descriptor.
    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  // WithPlatform sets the platform of the artifact descriptor.
    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