38 lines
787 B
Go
Raw Normal View History

2019-07-28 20:00:09 +01:00
// Package registry resolves names using the go-micro registry
2019-07-28 12:14:40 +01:00
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
2019-07-28 20:00:09 +01:00
func (r *Resolver) Resolve(name string) ([]*resolver.Record, error) {
2019-07-28 12:14:40 +01:00
reg := r.Registry
if reg == nil {
reg = registry.DefaultRegistry
}
2019-07-28 20:00:09 +01:00
services, err := reg.GetService(name)
2019-07-28 12:14:40 +01:00
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
}