2015-01-06 18:40:00 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
// Status can be used to query the Status endpoints
|
|
|
|
type Status struct {
|
|
|
|
c *Client
|
|
|
|
}
|
|
|
|
|
|
|
|
// Status returns a handle to the status endpoints
|
|
|
|
func (c *Client) Status() *Status {
|
|
|
|
return &Status{c}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Leader is used to query for a known leader
|
2020-07-29 16:09:15 +00:00
|
|
|
func (s *Status) LeaderWithQueryOptions(q *QueryOptions) (string, error) {
|
2015-01-06 18:40:00 +00:00
|
|
|
r := s.c.newRequest("GET", "/v1/status/leader")
|
2020-07-29 16:09:15 +00:00
|
|
|
|
|
|
|
if q != nil {
|
|
|
|
r.setQueryOptions(q)
|
|
|
|
}
|
|
|
|
|
2015-01-06 18:40:00 +00:00
|
|
|
_, resp, err := requireOK(s.c.doRequest(r))
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var leader string
|
|
|
|
if err := decodeBody(resp, &leader); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return leader, nil
|
|
|
|
}
|
|
|
|
|
2020-07-29 16:09:15 +00:00
|
|
|
func (s *Status) Leader() (string, error) {
|
|
|
|
return s.LeaderWithQueryOptions(nil)
|
|
|
|
}
|
|
|
|
|
2015-01-06 18:40:00 +00:00
|
|
|
// Peers is used to query for a known raft peers
|
2020-07-29 16:09:15 +00:00
|
|
|
func (s *Status) PeersWithQueryOptions(q *QueryOptions) ([]string, error) {
|
2015-01-06 18:40:00 +00:00
|
|
|
r := s.c.newRequest("GET", "/v1/status/peers")
|
2020-07-29 16:09:15 +00:00
|
|
|
|
|
|
|
if q != nil {
|
|
|
|
r.setQueryOptions(q)
|
|
|
|
}
|
|
|
|
|
2015-01-06 18:40:00 +00:00
|
|
|
_, resp, err := requireOK(s.c.doRequest(r))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var peers []string
|
|
|
|
if err := decodeBody(resp, &peers); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return peers, nil
|
|
|
|
}
|
2020-07-29 16:09:15 +00:00
|
|
|
|
|
|
|
func (s *Status) Peers() ([]string, error) {
|
|
|
|
return s.PeersWithQueryOptions(nil)
|
|
|
|
}
|