2018-12-06 21:19:05 +03:00
|
|
|
package gossip
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2018-12-19 00:57:16 +03:00
|
|
|
"github.com/hashicorp/memberlist"
|
2018-12-06 21:19:05 +03:00
|
|
|
"github.com/micro/go-micro/registry"
|
|
|
|
)
|
|
|
|
|
|
|
|
type contextSecretKey struct{}
|
|
|
|
|
|
|
|
// Secret specifies an encryption key. The value should be either
|
|
|
|
// 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256.
|
|
|
|
func Secret(k []byte) registry.Option {
|
2019-01-30 15:39:57 +03:00
|
|
|
return setRegistryOption(contextSecretKey{}, k)
|
2018-12-06 21:19:05 +03:00
|
|
|
}
|
2018-12-19 00:57:16 +03:00
|
|
|
|
|
|
|
type contextAddress struct{}
|
|
|
|
|
|
|
|
// Address to bind to - host:port
|
|
|
|
func Address(a string) registry.Option {
|
2019-01-30 15:39:57 +03:00
|
|
|
return setRegistryOption(contextAddress{}, a)
|
2018-12-19 00:57:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type contextConfig struct{}
|
|
|
|
|
|
|
|
// Config allow to inject a *memberlist.Config struct for configuring gossip
|
|
|
|
func Config(c *memberlist.Config) registry.Option {
|
2019-01-30 15:39:57 +03:00
|
|
|
return setRegistryOption(contextConfig{}, c)
|
2018-12-19 00:57:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type contextAdvertise struct{}
|
|
|
|
|
|
|
|
// The address to advertise for other gossip members - host:port
|
|
|
|
func Advertise(a string) registry.Option {
|
2019-01-30 15:39:57 +03:00
|
|
|
return setRegistryOption(contextAdvertise{}, a)
|
|
|
|
}
|
|
|
|
|
|
|
|
type contextContext struct{}
|
|
|
|
|
|
|
|
// Context specifies a context for the registry.
|
|
|
|
// Can be used to signal shutdown of the registry.
|
|
|
|
// Can be used for extra option values.
|
|
|
|
func Context(ctx context.Context) registry.Option {
|
|
|
|
return setRegistryOption(contextContext{}, ctx)
|
2018-12-19 00:57:16 +03:00
|
|
|
}
|