2015-12-09 21:23:16 +02:00
|
|
|
package selector
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/micro/go-micro/registry"
|
2016-01-06 18:25:12 +02:00
|
|
|
|
|
|
|
"golang.org/x/net/context"
|
2015-12-09 21:23:16 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Options struct {
|
|
|
|
Registry registry.Registry
|
2015-12-31 20:14:40 +02:00
|
|
|
|
2016-01-06 18:25:12 +02:00
|
|
|
// Other options for implementations of the interface
|
|
|
|
// can be stored in a context
|
|
|
|
Context context.Context
|
2015-12-09 21:23:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type SelectOptions struct {
|
|
|
|
Filters []SelectFilter
|
2015-12-31 20:14:40 +02:00
|
|
|
|
2016-01-06 18:25:12 +02:00
|
|
|
// Other options for implementations of the interface
|
|
|
|
// can be stored in a context
|
|
|
|
Context context.Context
|
2015-12-09 21:23:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Option used to initialise the selector
|
|
|
|
type Option func(*Options)
|
|
|
|
|
|
|
|
// SelectOption used when making a select call
|
|
|
|
type SelectOption func(*SelectOptions)
|
|
|
|
|
|
|
|
// Registry sets the registry used by the selector
|
|
|
|
func Registry(r registry.Registry) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Registry = r
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Filter adds a filter function to the list of filters
|
|
|
|
// used during the Select call.
|
|
|
|
func Filter(fn SelectFilter) SelectOption {
|
|
|
|
return func(o *SelectOptions) {
|
|
|
|
o.Filters = append(o.Filters, fn)
|
|
|
|
}
|
|
|
|
}
|