implement some gossip options

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2018-12-19 00:57:16 +03:00
parent f2efc685d3
commit 5bcdf189de
2 changed files with 69 additions and 10 deletions

View File

@@ -3,6 +3,7 @@ package gossip
import (
"context"
"github.com/hashicorp/memberlist"
"github.com/micro/go-micro/registry"
)
@@ -15,3 +16,30 @@ func Secret(k []byte) registry.Option {
o.Context = context.WithValue(o.Context, contextSecretKey{}, k)
}
}
type contextAddress struct{}
// Address to bind to - host:port
func Address(a string) registry.Option {
return func(o *registry.Options) {
o.Context = context.WithValue(o.Context, contextAddress{}, a)
}
}
type contextConfig struct{}
// Config allow to inject a *memberlist.Config struct for configuring gossip
func Config(c *memberlist.Config) registry.Option {
return func(o *registry.Options) {
o.Context = context.WithValue(o.Context, contextConfig{}, c)
}
}
type contextAdvertise struct{}
// The address to advertise for other gossip members - host:port
func Advertise(a string) registry.Option {
return func(o *registry.Options) {
o.Context = context.WithValue(o.Context, contextAdvertise{}, a)
}
}