micro/selector/options.go

45 lines
933 B
Go
Raw Normal View History

2015-12-09 22:23:16 +03:00
package selector
import (
"github.com/micro/go-micro/registry"
"golang.org/x/net/context"
2015-12-09 22:23:16 +03:00
)
type Options struct {
Registry registry.Registry
// Other options for implementations of the interface
// can be stored in a context
Context context.Context
2015-12-09 22:23:16 +03:00
}
type SelectOptions struct {
2016-04-23 22:15:01 +03:00
Filters []Filter
// Other options for implementations of the interface
// can be stored in a context
Context context.Context
2015-12-09 22:23:16 +03: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
}
}
2016-04-23 22:15:01 +03:00
// WithFilter adds a filter function to the list of filters
2015-12-09 22:23:16 +03:00
// used during the Select call.
2016-04-23 22:15:01 +03:00
func WithFilter(fn Filter) SelectOption {
2015-12-09 22:23:16 +03:00
return func(o *SelectOptions) {
o.Filters = append(o.Filters, fn)
}
}