|
@ -40,10 +40,10 @@ func (s *RaftServer) HandleFunc(pattern string, handler func(http.ResponseWriter |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (s *RaftServer) redirectToLeader(w http.ResponseWriter, req *http.Request) { |
|
|
func (s *RaftServer) redirectToLeader(w http.ResponseWriter, req *http.Request) { |
|
|
if s.topo.Leader() != "" { |
|
|
|
|
|
|
|
|
if leader, e := s.topo.Leader(); e == nil { |
|
|
//http.StatusMovedPermanently does not cause http POST following redirection
|
|
|
//http.StatusMovedPermanently does not cause http POST following redirection
|
|
|
glog.V(0).Infoln("Redirecting to", http.StatusMovedPermanently, "http://"+s.topo.Leader()+req.URL.Path) |
|
|
|
|
|
http.Redirect(w, req, "http://"+s.topo.Leader()+req.URL.Path, http.StatusMovedPermanently) |
|
|
|
|
|
|
|
|
glog.V(0).Infoln("Redirecting to", http.StatusMovedPermanently, "http://"+leader+req.URL.Path) |
|
|
|
|
|
http.Redirect(w, req, "http://"+leader+req.URL.Path, http.StatusMovedPermanently) |
|
|
} else { |
|
|
} else { |
|
|
glog.V(0).Infoln("Error: Leader Unknown") |
|
|
glog.V(0).Infoln("Error: Leader Unknown") |
|
|
http.Error(w, "Leader unknown", http.StatusInternalServerError) |
|
|
http.Error(w, "Leader unknown", http.StatusInternalServerError) |
|
@ -53,7 +53,11 @@ func (s *RaftServer) redirectToLeader(w http.ResponseWriter, req *http.Request) |
|
|
func (s *RaftServer) statusHandler(w http.ResponseWriter, r *http.Request) { |
|
|
func (s *RaftServer) statusHandler(w http.ResponseWriter, r *http.Request) { |
|
|
m := make(map[string]interface{}) |
|
|
m := make(map[string]interface{}) |
|
|
m["IsLeader"] = s.topo.IsLeader() |
|
|
m["IsLeader"] = s.topo.IsLeader() |
|
|
m["Leader"] = s.topo.Leader() |
|
|
|
|
|
|
|
|
if leader, e := s.topo.Leader(); e == nil { |
|
|
|
|
|
m["Leader"] = leader |
|
|
|
|
|
} else { |
|
|
|
|
|
m["Leader"] = "" |
|
|
|
|
|
} |
|
|
m["Peers"] = s.Peers() |
|
|
m["Peers"] = s.Peers() |
|
|
writeJsonQuiet(w, r, m) |
|
|
writeJsonQuiet(w, r, m) |
|
|
} |
|
|
} |