From 68764ebafc556123884a52cad47fc3b127d4b54a Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 24 Jun 2019 15:30:17 +0100 Subject: [PATCH] Add registry resolver --- network/resolver/registry/registry.go | 37 +++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 network/resolver/registry/registry.go diff --git a/network/resolver/registry/registry.go b/network/resolver/registry/registry.go new file mode 100644 index 00000000..c7ef796a --- /dev/null +++ b/network/resolver/registry/registry.go @@ -0,0 +1,37 @@ +// Package registry resolves ids using the go-micro registry +package registry + +import ( + "github.com/micro/go-micro/network/resolver" + "github.com/micro/go-micro/registry" +) + +type Resolver struct { + // Registry is the registry to use otherwise we use the defaul + Registry registry.Registry +} + +// Resolve assumes ID is a domain name e.g micro.mu +func (r *Resolver) Resolve(id string) ([]*resolver.Record, error) { + reg := r.Registry + if reg == nil { + reg = registry.DefaultRegistry + } + + services, err := reg.GetService(id) + if err != nil { + return nil, err + } + + var records []*resolver.Record + + for _, service := range services { + for _, node := range service.Nodes { + records = append(records, &resolver.Record{ + Address: node.Address, + }) + } + } + + return records, nil +}