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