raft_server_handlers.go 498 B

12345678910111213141516171819202122
  1. package weed_server
  2. import (
  3. "net/http"
  4. )
  5. type ClusterStatusResult struct {
  6. IsLeader bool `json:"IsLeader,omitempty"`
  7. Leader string `json:"Leader,omitempty"`
  8. Peers []string `json:"Peers,omitempty"`
  9. }
  10. func (s *RaftServer) StatusHandler(w http.ResponseWriter, r *http.Request) {
  11. ret := ClusterStatusResult{
  12. IsLeader: s.topo.IsLeader(),
  13. Peers: s.Peers(),
  14. }
  15. if leader, e := s.topo.Leader(); e == nil {
  16. ret.Leader = leader
  17. }
  18. oldWriteJsonQuiet(w, r, http.StatusOK, ret)
  19. }