status.go 932 B

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