github.com/annwntech/go-micro/v2@v2.9.5/network/resolver/static/static.go (about)

     1  // Package static is a static resolver
     2  package registry
     3  
     4  import (
     5  	"github.com/annwntech/go-micro/v2/network/resolver"
     6  )
     7  
     8  // Resolver returns a static list of nodes. In the event the node list
     9  // is not present it will return the name of the network passed in.
    10  type Resolver struct {
    11  	// A static list of nodes
    12  	Nodes []string
    13  }
    14  
    15  // Resolve returns the list of nodes
    16  func (r *Resolver) Resolve(name string) ([]*resolver.Record, error) {
    17  	// if there are no nodes just return the name
    18  	if len(r.Nodes) == 0 {
    19  		return []*resolver.Record{
    20  			{Address: name},
    21  		}, nil
    22  	}
    23  
    24  	records := make([]*resolver.Record, 0, len(r.Nodes))
    25  
    26  	for _, node := range r.Nodes {
    27  		records = append(records, &resolver.Record{
    28  			Address: node,
    29  		})
    30  	}
    31  
    32  	return records, nil
    33  }