mirror of
https://github.com/go-micro/go-micro.git
synced 2025-08-10 21:52:01 +02:00
Allow configurable addresses for everything
This commit is contained in:
@@ -138,9 +138,12 @@ func (c *ConsulRegistry) Watch() {
|
||||
NewConsulWatcher(c)
|
||||
}
|
||||
|
||||
func NewConsulRegistry() Registry {
|
||||
func NewConsulRegistry(addrs []string, opts ...Options) Registry {
|
||||
config := consul.DefaultConfig()
|
||||
client, _ := consul.NewClient(config)
|
||||
if len(addrs) > 0 {
|
||||
config.Address = addrs[0]
|
||||
}
|
||||
|
||||
cr := &ConsulRegistry{
|
||||
Address: config.Address,
|
||||
|
@@ -115,9 +115,14 @@ func (c *KubernetesRegistry) NewNode(id, address string, port int) Node {
|
||||
}
|
||||
}
|
||||
|
||||
func NewKubernetesRegistry() Registry {
|
||||
func NewKubernetesRegistry(addrs []string, opts ...Options) Registry {
|
||||
host := "http://" + os.Getenv("KUBERNETES_RO_SERVICE_HOST") + ":" + os.Getenv("KUBERNETES_RO_SERVICE_PORT")
|
||||
if len(addrs) > 0 {
|
||||
host = addrs[0]
|
||||
}
|
||||
|
||||
client, _ := k8s.New(&k8s.Config{
|
||||
Host: "http://" + os.Getenv("KUBERNETES_RO_SERVICE_HOST") + ":" + os.Getenv("KUBERNETES_RO_SERVICE_PORT"),
|
||||
Host: host,
|
||||
})
|
||||
|
||||
kr := &KubernetesRegistry{
|
||||
|
@@ -9,8 +9,12 @@ type Registry interface {
|
||||
NewNode(string, string, int) Node
|
||||
}
|
||||
|
||||
type options struct{}
|
||||
|
||||
type Options func(*options)
|
||||
|
||||
var (
|
||||
DefaultRegistry = NewConsulRegistry()
|
||||
DefaultRegistry = NewConsulRegistry([]string{})
|
||||
)
|
||||
|
||||
func Register(s Service) error {
|
||||
|
Reference in New Issue
Block a user