github.com/afbjorklund/moby@v20.10.5+incompatible/pkg/discovery/nodes/nodes.go (about)

     1  package nodes // import "github.com/docker/docker/pkg/discovery/nodes"
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  	"time"
     7  
     8  	"github.com/docker/docker/pkg/discovery"
     9  )
    10  
    11  // Discovery is exported
    12  type Discovery struct {
    13  	entries discovery.Entries
    14  }
    15  
    16  func init() {
    17  	Init()
    18  }
    19  
    20  // Init is exported
    21  func Init() {
    22  	discovery.Register("nodes", &Discovery{})
    23  }
    24  
    25  // Initialize is exported
    26  func (s *Discovery) Initialize(uris string, _ time.Duration, _ time.Duration, _ map[string]string) error {
    27  	for _, input := range strings.Split(uris, ",") {
    28  		for _, ip := range discovery.Generate(input) {
    29  			entry, err := discovery.NewEntry(ip)
    30  			if err != nil {
    31  				return fmt.Errorf("%s, please check you are using the correct discovery (missing token:// ?)", err.Error())
    32  			}
    33  			s.entries = append(s.entries, entry)
    34  		}
    35  	}
    36  
    37  	return nil
    38  }
    39  
    40  // Watch is exported
    41  func (s *Discovery) Watch(stopCh <-chan struct{}) (<-chan discovery.Entries, <-chan error) {
    42  	ch := make(chan discovery.Entries)
    43  	go func() {
    44  		defer close(ch)
    45  		ch <- s.entries
    46  		<-stopCh
    47  	}()
    48  	return ch, nil
    49  }
    50  
    51  // Register is exported
    52  func (s *Discovery) Register(addr string) error {
    53  	return discovery.ErrNotImplemented
    54  }