micro/resolver/registry/registry.go

35 lines
859 B
Go
Raw Normal View History

// Package register resolves names using the micro register
package register // import "go.unistack.org/micro/v4/resolver/registry"
2019-07-28 14:14:40 +03:00
import (
"context"
"go.unistack.org/micro/v4/register"
"go.unistack.org/micro/v4/resolver"
2019-07-28 14:14:40 +03:00
)
// Resolver is a register network resolver
2019-07-28 14:14:40 +03:00
type Resolver struct {
// Register is the register to use otherwise we use the defaul
Register register.Register
2019-07-28 14:14:40 +03:00
}
// Resolve assumes ID is a domain name e.g micro.mu
2019-07-28 22:00:09 +03:00
func (r *Resolver) Resolve(name string) ([]*resolver.Record, error) {
services, err := r.Register.LookupService(context.TODO(), name)
2019-07-28 14:14:40 +03:00
if err != nil {
return nil, err
}
records := make([]*resolver.Record, 0, len(services))
2019-07-28 14:14:40 +03:00
for _, service := range services {
for _, node := range service.Nodes {
records = append(records, &resolver.Record{
Address: node.Address,
})
}
}
return records, nil
}