k3s/vendor/github.com/canonical/go-dqlite/client/leader.go

30 lines
596 B
Go
Raw Normal View History

2019-11-08 21:45:10 +00:00
package client
import (
"context"
"github.com/canonical/go-dqlite/internal/protocol"
)
// FindLeader returns a Client connected to the current cluster leader, if any.
func FindLeader(ctx context.Context, store NodeStore, options ...Option) (*Client, error) {
o := defaultOptions()
for _, option := range options {
option(o)
}
config := protocol.Config{
2020-04-23 20:34:44 +00:00
Dial: o.DialFunc,
2019-11-08 21:45:10 +00:00
}
connector := protocol.NewConnector(0, store, config, o.LogFunc)
protocol, err := connector.Connect(ctx)
if err != nil {
return nil, err
}
client := &Client{protocol: protocol}
return client, nil
}