Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame^] | 1 | package api |
| 2 | |
| 3 | // Status can be used to query the Status endpoints |
| 4 | type Status struct { |
| 5 | c *Client |
| 6 | } |
| 7 | |
| 8 | // Status returns a handle to the status endpoints |
| 9 | func (c *Client) Status() *Status { |
| 10 | return &Status{c} |
| 11 | } |
| 12 | |
| 13 | // Leader is used to query for a known leader |
| 14 | func (s *Status) Leader() (string, error) { |
| 15 | r := s.c.newRequest("GET", "/v1/status/leader") |
| 16 | _, resp, err := requireOK(s.c.doRequest(r)) |
| 17 | if err != nil { |
| 18 | return "", err |
| 19 | } |
| 20 | defer resp.Body.Close() |
| 21 | |
| 22 | var leader string |
| 23 | if err := decodeBody(resp, &leader); err != nil { |
| 24 | return "", err |
| 25 | } |
| 26 | return leader, nil |
| 27 | } |
| 28 | |
| 29 | // Peers is used to query for a known raft peers |
| 30 | func (s *Status) Peers() ([]string, error) { |
| 31 | r := s.c.newRequest("GET", "/v1/status/peers") |
| 32 | _, resp, err := requireOK(s.c.doRequest(r)) |
| 33 | if err != nil { |
| 34 | return nil, err |
| 35 | } |
| 36 | defer resp.Body.Close() |
| 37 | |
| 38 | var peers []string |
| 39 | if err := decodeBody(resp, &peers); err != nil { |
| 40 | return nil, err |
| 41 | } |
| 42 | return peers, nil |
| 43 | } |