Esempio n. 1
0
func (d *dialer) createSet(name string) (*set, error) {
	d.mtx.Lock()
	defer d.mtx.Unlock()

	if services, ok := d.sets[name]; ok {
		return services, nil
	}

	services, err := d.c.NewServiceSet(name)
	if err != nil {
		return nil, err
	}
	s := &set{services, balancer.Random(services, nil)}
	d.sets[name] = s
	return s, nil
}
Esempio n. 2
0
func NewServerWithDiscoverd(uri string, d DiscoverdClient) (*Server, error) {
	u, err := url.Parse(uri)
	if err != nil {
		return nil, err
	}
	if u.Scheme != "discoverd+http" {
		return nil, errors.New("resource: uri scheme must be discoverd+http")
	}

	set, err := d.NewServiceSet(u.Host)
	if err != nil {
		return nil, err
	}
	s := &Server{
		path: u.Path,
		set:  set,
		lb:   balancer.Random(set, nil),
	}
	return s, err
}