...

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

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

     1  package cache
     2  
     3  import (
     4  	"github.com/google/go-containerregistry/pkg/v1/remote"
     5  )
     6  
     7  // Option
     8  type Option = func(*options)
     9  
    10  type options struct {
    11  	memoryCacheSize int
    12  	recorder        Recorder
    13  	puller          *remote.Puller
    14  }
    15  
    16  func WithMemoryCacheSize(limit int) Option {
    17  	return func(o *options) {
    18  		o.memoryCacheSize = limit
    19  	}
    20  }
    21  
    22  // WithPuller sets the [remote.Puller] used by the cache. If provided, the
    23  // Puller takes precedence over any Pullers passed to specific Get() calls
    24  // using [remote.Reuse]
    25  func WithPuller(p *remote.Puller) Option {
    26  	return func(o *options) {
    27  		o.puller = p
    28  	}
    29  }
    30  
    31  func WithRecorder(r Recorder) Option {
    32  	return func(o *options) {
    33  		o.recorder = r
    34  	}
    35  }
    36  
    37  func makeOptions(opts ...Option) options {
    38  	o := options{}
    39  	for _, opt := range opts {
    40  		opt(&o)
    41  	}
    42  	return o
    43  }
    44  
    45  // GetOption allows changing the behavior of individual Get() operations.
    46  type GetOption = func(*getOptions)
    47  
    48  type getOptions struct {
    49  	remoteOpts []remote.Option
    50  	resolveTag bool
    51  }
    52  
    53  // WithRemoteOpts sets the remote options for an individual Get()
    54  func WithRemoteOpts(opts ...remote.Option) GetOption {
    55  	return func(o *getOptions) {
    56  		if len(opts) > 0 {
    57  			o.remoteOpts = opts
    58  		}
    59  	}
    60  }
    61  
    62  // ResolveTag will reach out to the registry to resolve a tag reference before
    63  // checking local caches, ensuring that up-to-date tag values wind up in the cache.
    64  func ResolveTag() GetOption {
    65  	return func(o *getOptions) {
    66  		o.resolveTag = true
    67  	}
    68  }
    69  
    70  func makeGetOptions(opts ...GetOption) getOptions {
    71  	o := getOptions{}
    72  	for _, opt := range opts {
    73  		opt(&o)
    74  	}
    75  	return o
    76  }
    77  

View as plain text