micro/resolver/registry/registry.go
Vasiliy Tolstov d18bf3dab9 many fixes for lint and context.Context usage
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-11-03 01:57:11 +03:00

35 lines
820 B
Go

// Package registry resolves names using the go-micro registry
package registry
import (
"context"
"github.com/unistack-org/micro/v3/registry"
"github.com/unistack-org/micro/v3/resolver"
)
// Resolver is a registry network resolver
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(name string) ([]*resolver.Record, error) {
services, err := r.Registry.GetService(context.TODO(), name)
if err != nil {
return nil, err
}
records := make([]*resolver.Record, 0, len(services))
for _, service := range services {
for _, node := range service.Nodes {
records = append(records, &resolver.Record{
Address: node.Address,
})
}
}
return records, nil
}