func (c *cluster) membersList(status memberStatus) []string {
	c.RLock()
	defer c.RUnlock()
	var list []string
	for _, m := range c.members {
		if m.status == status {
			list = append(list, m.endpoint)
		}
	}
	return list
}
memberList returns a list of members of a specified status
package marathon
import (
	"fmt"
	"net/url"
	"strings"
	"sync"
	"time"
)
const (
	memberStatusUp   = 0
	memberStatusDown = 1
)
type memberStatus int
type cluster struct {
	sync.RWMutex
	members []*member
	client *httpClient
}
type member struct {
	endpoint string
	status memberStatus
}
func newCluster(client *httpClient, marathonURL string, isDCOS bool) (*cluster, error) {
	var members []*member
	var defaultProto string
	for _, endpoint := range strings.Split(marathonURL, ",") {
		if endpoint == "" {
			return nil, newInvalidEndpointError("endpoint is blank")
		}
		if !strings.HasPrefix(endpoint, "http://") && !strings.HasPrefix(endpoint, "https://") {
			if defaultProto == "" {
				return nil, newInvalidEndpointError("missing scheme on (first) endpoint")
			}
			endpoint = fmt.Sprintf("%s://%s", defaultProto, endpoint)
		}
		u, err := url.Parse(endpoint)
		if err != nil {
			return nil, newInvalidEndpointError("invalid endpoint '%s': %s", endpoint, err)
		}
		if defaultProto == "" {
			defaultProto = u.Scheme
		}
		if u.Host == "" {
			return nil, newInvalidEndpointError("endpoint: %s must have a host", endpoint)
		}
		if isDCOS && strings.TrimLeft(u.Path, "/") == "" {
			u.Path = defaultDCOSPath
		}
		members = append(members, &member{endpoint: u.String()})
	}
	return &cluster{
		client:  client,
		members: members,
	}, nil
}
func (c *cluster) getMember() (string, error) {
	c.RLock()
	defer c.RUnlock()
	for _, n := range c.members {
		if n.status == memberStatusUp {
			return n.endpoint, nil
		}
	}
	return "", ErrMarathonDown
}
func (c *cluster) markDown(endpoint string) {
	c.Lock()
	defer c.Unlock()
	for _, n := range c.members {
		if n.status == memberStatusUp && n.endpoint == endpoint {
			n.status = memberStatusDown
			go c.healthCheckNode(n)
			break
		}
	}
}
func (c *cluster) healthCheckNode(node *member) {
	for {
		req, err := c.client.buildMarathonRequest("GET", node.endpoint, "/ping", nil)
		if err == nil {
			res, err := c.client.Do(req)
			if err == nil && res.StatusCode == 200 {
				break
			}
		}
		<-time.After(time.Duration(5 * time.Second))
	}
	c.Lock()
	defer c.Unlock()
	node.status = memberStatusUp
}
func (c *cluster) activeMembers() []string {
	return c.membersList(memberStatusUp)
}
func (c *cluster) nonActiveMembers() []string {
	return c.membersList(memberStatusDown)
}