2019-08-23 19:24:21 +03:00
|
|
|
// Package static is a static resolver
|
2020-08-10 00:11:57 +03:00
|
|
|
package static
|
2019-08-23 19:24:21 +03:00
|
|
|
|
|
|
|
import (
|
2020-08-23 17:00:27 +03:00
|
|
|
"github.com/micro/go-micro/v3/network/resolver"
|
2019-08-23 19:24:21 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// Resolver returns a static list of nodes. In the event the node list
|
|
|
|
// is not present it will return the name of the network passed in.
|
|
|
|
type Resolver struct {
|
|
|
|
// A static list of nodes
|
|
|
|
Nodes []string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resolve returns the list of nodes
|
|
|
|
func (r *Resolver) Resolve(name string) ([]*resolver.Record, error) {
|
|
|
|
// if there are no nodes just return the name
|
|
|
|
if len(r.Nodes) == 0 {
|
|
|
|
return []*resolver.Record{
|
|
|
|
{Address: name},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2019-11-11 03:03:51 +03:00
|
|
|
records := make([]*resolver.Record, 0, len(r.Nodes))
|
2019-08-23 19:24:21 +03:00
|
|
|
|
|
|
|
for _, node := range r.Nodes {
|
|
|
|
records = append(records, &resolver.Record{
|
|
|
|
Address: node,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return records, nil
|
|
|
|
}
|