First commit in strategy rework

This commit is contained in:
Asim
2016-05-03 22:06:19 +01:00
parent b13361d010
commit 0a4484b406
11 changed files with 235 additions and 284 deletions

View File

@@ -8,6 +8,7 @@ import (
type Options struct {
Registry registry.Registry
Strategy Strategy
// Other options for implementations of the interface
// can be stored in a context
@@ -15,7 +16,8 @@ type Options struct {
}
type SelectOptions struct {
Filters []Filter
Filters []Filter
Strategy Strategy
// Other options for implementations of the interface
// can be stored in a context
@@ -35,6 +37,13 @@ func Registry(r registry.Registry) Option {
}
}
// SetStrategy sets the default strategy for the selector
func SetStrategy(fn Strategy) Option {
return func(o *Options) {
o.Strategy = fn
}
}
// WithFilter adds a filter function to the list of filters
// used during the Select call.
func WithFilter(fn ...Filter) SelectOption {
@@ -42,3 +51,10 @@ func WithFilter(fn ...Filter) SelectOption {
o.Filters = append(o.Filters, fn...)
}
}
// Strategy sets the selector strategy
func WithStrategy(fn Strategy) SelectOption {
return func(o *SelectOptions) {
o.Strategy = fn
}
}