Add flag for registry service client

This commit is contained in:
Asim Aslam 2019-09-25 11:09:19 +01:00
parent 624d37cf13
commit 7fe64192a7
2 changed files with 16 additions and 6 deletions

View File

@ -30,6 +30,7 @@ import (
"github.com/micro/go-micro/registry/gossip" "github.com/micro/go-micro/registry/gossip"
"github.com/micro/go-micro/registry/mdns" "github.com/micro/go-micro/registry/mdns"
rmem "github.com/micro/go-micro/registry/memory" rmem "github.com/micro/go-micro/registry/memory"
regSrv "github.com/micro/go-micro/registry/service"
// selectors // selectors
"github.com/micro/go-micro/client/selector" "github.com/micro/go-micro/client/selector"
@ -190,6 +191,8 @@ var (
} }
DefaultRegistries = map[string]func(...registry.Option) registry.Registry{ DefaultRegistries = map[string]func(...registry.Option) registry.Registry{
"go.micro.registry": regSrv.NewRegistry,
"service": regSrv.NewRegistry,
"consul": consul.NewRegistry, "consul": consul.NewRegistry,
"gossip": gossip.NewRegistry, "gossip": gossip.NewRegistry,
"mdns": mdns.NewRegistry, "mdns": mdns.NewRegistry,

View File

@ -134,7 +134,14 @@ func NewRegistry(opts ...registry.Option) registry.Registry {
o(&options) o(&options)
} }
// use mdns to find the service registry // the registry address
addrs := options.Addrs
if len(addrs) == 0 {
addrs = []string{"127.0.0.1:8000"}
}
// use mdns as a fall back in case its used
mReg := registry.NewRegistry() mReg := registry.NewRegistry()
// create new client with mdns // create new client with mdns
@ -149,7 +156,7 @@ func NewRegistry(opts ...registry.Option) registry.Registry {
return &serviceRegistry{ return &serviceRegistry{
opts: options, opts: options,
name: name, name: name,
address: options.Addrs, address: addrs,
client: pb.NewRegistryService(name, cli), client: pb.NewRegistryService(name, cli),
} }
} }