nodes.go 1.1 KB

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