Add a static network node resolver
This commit is contained in:
parent
718780367e
commit
1b0295de0d
33
network/resolver/static/static.go
Normal file
33
network/resolver/static/static.go
Normal file
@ -0,0 +1,33 @@
|
||||
// Package static is a static resolver
|
||||
package registry
|
||||
|
||||
import (
|
||||
"github.com/micro/go-micro/network/resolver"
|
||||
)
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
var records []*resolver.Record
|
||||
|
||||
for _, node := range r.Nodes {
|
||||
records = append(records, &resolver.Record{
|
||||
Address: node,
|
||||
})
|
||||
}
|
||||
|
||||
return records, nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user