...

Source file src/edge-infra.dev/pkg/f8n/warehouse/oci/layer/options.go

Documentation: edge-infra.dev/pkg/f8n/warehouse/oci/layer

     1  package layer
     2  
     3  import (
     4  	wh "edge-infra.dev/pkg/f8n/warehouse"
     5  	"edge-infra.dev/pkg/f8n/warehouse/capability"
     6  )
     7  
     8  // Option is a Layer constructor option.
     9  type Option func(*options)
    10  
    11  type options struct {
    12  	annos map[string]string
    13  	cap   capability.Capability
    14  }
    15  
    16  func makeOptions(opts ...Option) *options {
    17  	o := &options{}
    18  	for _, opt := range opts {
    19  		opt(o)
    20  	}
    21  
    22  	// if runtime capability is set, add the appropriate annotation
    23  	if o.cap != "" {
    24  		if o.annos == nil {
    25  			o.annos = make(map[string]string)
    26  		}
    27  		o.annos[wh.AnnotationLayerRuntimeCapability] = string(o.cap)
    28  	}
    29  
    30  	return o
    31  }
    32  
    33  // WithAnnotations sets annotations on the result Layer. Additional calls are
    34  // all appended to the same annotation map.
    35  func WithAnnotations(a map[string]string) Option {
    36  	return func(o *options) {
    37  		if o.annos == nil {
    38  			o.annos = make(map[string]string)
    39  		}
    40  
    41  		for k, v := range a {
    42  			o.annos[k] = v
    43  		}
    44  	}
    45  }
    46  
    47  // ForCapability creates a Layer for a specific runtime capability.
    48  func ForCapability(c capability.Capability) Option {
    49  	return func(o *options) { o.cap = c }
    50  }
    51  

View as plain text