func (c *LeaderClient) Do(msg proto.Message, ctx context.Context, opts ...client.RequestOpt) (client.Response, error) {
	for {
		c.RLock()
		endpoint := c.endpoint
		lastSeq := c.endpointSeq
		c.RUnlock()
		if endpoint != "" {
			leader := c.clientProvider.New(endpoint, c.clientOpts...)
			if resp, err := leader.Do(msg, ctx, opts...); err == nil {
				return resp, err
			} else {
				c.log.Log("event", "call", "err", err)
			}
		}
		c.Lock()
		if c.endpointSeq > lastSeq {
			c.Unlock()
			continue
		}
		if resp, newEndpoint, err := c.findLeader(msg, ctx, opts...); err != nil {
			c.Unlock()
			return nil, err
		} else {
			c.endpoint = newEndpoint
			c.endpointSeq = lastSeq + 1
			c.Unlock()
			return resp, nil
		}
	}
}
Send message to current leader.
Handles leader (re)detection and retries on error
package leader
import (
	"context"
	"net/url"
	"sync"
	"github.com/gogo/protobuf/proto"
	"github.com/ondrej-smola/mesos-go-http/lib/client"
	"github.com/ondrej-smola/mesos-go-http/lib/log"
	"github.com/pkg/errors"
)
type (
	Opt func(*LeaderClient)
	LeaderClient struct {
		clientOpts     []client.DefaultClientOpt
		clientProvider client.Provider
		maxRedirects   int
		masters        []string
		log            log.Logger
		sync.RWMutex
		endpoint    string
		endpointSeq uint64  
	}
)
func WithClientProvider(p client.Provider) Opt {
	return func(l *LeaderClient) {
		l.clientProvider = p
	}
}
func WithClientOpts(opts ...client.DefaultClientOpt) Opt {
	return func(l *LeaderClient) {
		l.clientOpts = opts
	}
}
func WithMaxRedirects(count int) Opt {
	return func(l *LeaderClient) {
		l.maxRedirects = count
	}
}
func WithLogger(l log.Logger) Opt {
	return func(c *LeaderClient) {
		c.log = l
	}
}
func New(endpoints []string, opts ...Opt) *LeaderClient {
	l := &LeaderClient{
		log:            log.NewNopLogger(),
		masters:        endpoints,
		clientProvider: client.NewProvider(),
		maxRedirects:   5,
	}
	for _, o := range opts {
		o(l)
	}
	return l
}