micro/resolver/registry/registry.go
Vasiliy Tolstov 5eb0e56373 move all imports to own domain
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2021-10-02 19:55:07 +03:00

35 lines
859 B
Go

// Package register resolves names using the micro register
package register // import "go.unistack.org/micro/v3/resolver/registry"
import (
"context"
"go.unistack.org/micro/v3/register"
"go.unistack.org/micro/v3/resolver"
)
// Resolver is a register network resolver
type Resolver struct {
// Register is the register to use otherwise we use the defaul
Register register.Register
}
// Resolve assumes ID is a domain name e.g micro.mu
func (r *Resolver) Resolve(name string) ([]*resolver.Record, error) {
services, err := r.Register.LookupService(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
}