1
0
mirror of https://github.com/go-kratos/kratos.git synced 2026-05-22 10:15:24 +02:00

feat: add selector and filters examples (#1485)

* add selector examples and filters
This commit is contained in:
longxboy
2021-09-23 17:42:21 +08:00
committed by GitHub
parent 25f448794d
commit feeec630d7
11 changed files with 348 additions and 25 deletions
+21 -1
View File
@@ -18,13 +18,33 @@ const (
var _ selector.Balancer = &Balancer{}
// WithFilter with select filters
func WithFilter(filters ...selector.Filter) Option {
return func(o *options) {
o.filters = filters
}
}
// Option is random builder option.
type Option func(o *options)
// options is random builder options
type options struct {
filters []selector.Filter
}
// New creates a p2c selector.
func New() selector.Selector {
func New(opts ...Option) selector.Selector {
var option options
for _, opt := range opts {
opt(&option)
}
return &selector.Default{
NodeBuilder: &ewma.Builder{},
Balancer: &Balancer{
r: rand.New(rand.NewSource(time.Now().UnixNano())),
},
Filters: option.filters,
}
}