Merge pull request #783 from micro/service

Add flag for registry service client
This commit is contained in:
Asim Aslam 2019-09-25 11:14:17 +01:00 committed by GitHub
commit be5799b09f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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/mdns"
rmem "github.com/micro/go-micro/registry/memory"
regSrv "github.com/micro/go-micro/registry/service"
// selectors
"github.com/micro/go-micro/client/selector"
@ -190,10 +191,12 @@ var (
}
DefaultRegistries = map[string]func(...registry.Option) registry.Registry{
"consul": consul.NewRegistry,
"gossip": gossip.NewRegistry,
"mdns": mdns.NewRegistry,
"memory": rmem.NewRegistry,
"go.micro.registry": regSrv.NewRegistry,
"service": regSrv.NewRegistry,
"consul": consul.NewRegistry,
"gossip": gossip.NewRegistry,
"mdns": mdns.NewRegistry,
"memory": rmem.NewRegistry,
}
DefaultSelectors = map[string]func(...selector.Option) selector.Selector{

View File

@ -134,7 +134,14 @@ func NewRegistry(opts ...registry.Option) registry.Registry {
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()
// create new client with mdns
@ -149,7 +156,7 @@ func NewRegistry(opts ...registry.Option) registry.Registry {
return &serviceRegistry{
opts: options,
name: name,
address: options.Addrs,
address: addrs,
client: pb.NewRegistryService(name, cli),
}
}