go-micro.dev/v5@v5.12.0/selector/options.go (about)

     1  package selector
     2  
     3  import (
     4  	"context"
     5  
     6  	"go-micro.dev/v5/logger"
     7  	"go-micro.dev/v5/registry"
     8  )
     9  
    10  type Options struct {
    11  	Registry registry.Registry
    12  	Strategy Strategy
    13  
    14  	// Other options for implementations of the interface
    15  	// can be stored in a context
    16  	Context context.Context
    17  	// Logger is the underline logger
    18  	Logger logger.Logger
    19  }
    20  
    21  type SelectOptions struct {
    22  
    23  	// Other options for implementations of the interface
    24  	// can be stored in a context
    25  	Context  context.Context
    26  	Strategy Strategy
    27  
    28  	Filters []Filter
    29  }
    30  
    31  type Option func(*Options)
    32  
    33  // SelectOption used when making a select call.
    34  type SelectOption func(*SelectOptions)
    35  
    36  // Registry sets the registry used by the selector.
    37  func Registry(r registry.Registry) Option {
    38  	return func(o *Options) {
    39  		o.Registry = r
    40  	}
    41  }
    42  
    43  // SetStrategy sets the default strategy for the selector.
    44  func SetStrategy(fn Strategy) Option {
    45  	return func(o *Options) {
    46  		o.Strategy = fn
    47  	}
    48  }
    49  
    50  // WithFilter adds a filter function to the list of filters
    51  // used during the Select call.
    52  func WithFilter(fn ...Filter) SelectOption {
    53  	return func(o *SelectOptions) {
    54  		o.Filters = append(o.Filters, fn...)
    55  	}
    56  }
    57  
    58  // Strategy sets the selector strategy.
    59  func WithStrategy(fn Strategy) SelectOption {
    60  	return func(o *SelectOptions) {
    61  		o.Strategy = fn
    62  	}
    63  }
    64  
    65  // WithLogger sets the underline logger.
    66  func WithLogger(l logger.Logger) Option {
    67  	return func(o *Options) {
    68  		o.Logger = l
    69  	}
    70  }