func newDiscovery(durl, dproxyurl string, id types.ID) (*discovery, error) { u, err := url.Parse(durl) if err != nil { return nil, err } token := u.Path u.Path = "" pf, err := newProxyFunc(dproxyurl) if err != nil { return nil, err } cfg := client.Config{ Transport: &http.Transport{Proxy: pf}, Endpoints: []string{u.String()}, } c, err := client.New(cfg) if err != nil { return nil, err } dc := client.NewKeysAPIWithPrefix(c, "") return &discovery{ cluster: token, c: dc, id: id, url: u, clock: clockwork.NewRealClock(), }, nil }
func getPeersFromDiscoveryURL(discoverURL string) ([]string, error) { if discoverURL == "" { return nil, nil } u, err := url.Parse(discoverURL) if err != nil { return nil, err } token := u.Path u.Path = "" cfg := client.Config{ Transport: &http.Transport{}, Endpoints: []string{u.String()}, } c, err := client.New(cfg) if err != nil { return nil, err } dc := client.NewKeysAPIWithPrefix(c, "") ctx, cancel := context.WithTimeout(context.Background(), client.DefaultRequestTimeout) resp, err := dc.Get(ctx, token, nil) cancel() if err != nil { return nil, err } peers := make([]string, 0) // append non-config keys to peers for _, n := range resp.Node.Nodes { if g := path.Base(n.Key); g == "_config" || g == "_state" { continue } peers = append(peers, n.Value) } return peers, nil }