mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
refactor add wrapper function
This commit is contained in:
@@ -115,7 +115,7 @@ func (s *PeerServer) ListenAndServe(snapshot bool, cluster []string) {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Rejoin the previous cluster
|
// Rejoin the previous cluster
|
||||||
cluster = s.registry.URLs(s.Leader(), s.name, s.registry.peerURL)
|
cluster = s.registry.PeerURLs(s.Leader(), s.name)
|
||||||
for i := 0; i < len(cluster); i++ {
|
for i := 0; i < len(cluster); i++ {
|
||||||
u, err := url.Parse(cluster[i])
|
u, err := url.Parse(cluster[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -111,8 +111,18 @@ func (r *Registry) peerURL(name string) (string, bool) {
|
|||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Retrieves the Client URLs for all nodes.
|
||||||
|
func (r *Registry) ClientURLs(leaderName, selfName string) []string {
|
||||||
|
return r.urls(leaderName, selfName, r.clientURL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieves the Peer URLs for all nodes.
|
||||||
|
func (r *Registry) PeerURLs(leaderName, selfName string) []string {
|
||||||
|
return r.urls(leaderName, selfName, r.peerURL)
|
||||||
|
}
|
||||||
|
|
||||||
// Retrieves the URLs for all nodes using url function.
|
// Retrieves the URLs for all nodes using url function.
|
||||||
func (r *Registry) URLs(leaderName, selfName string, url func(name string) (string, bool)) []string {
|
func (r *Registry) urls(leaderName, selfName string, url func(name string) (string, bool)) []string {
|
||||||
r.Lock()
|
r.Lock()
|
||||||
defer r.Unlock()
|
defer r.Unlock()
|
||||||
|
|
||||||
|
|||||||
@@ -258,7 +258,7 @@ func (s *Server) GetLeaderHandler(w http.ResponseWriter, req *http.Request) erro
|
|||||||
|
|
||||||
// Handler to return all the known machines in the current cluster.
|
// Handler to return all the known machines in the current cluster.
|
||||||
func (s *Server) GetMachinesHandler(w http.ResponseWriter, req *http.Request) error {
|
func (s *Server) GetMachinesHandler(w http.ResponseWriter, req *http.Request) error {
|
||||||
machines := s.registry.URLs(s.peerServer.Leader(), s.name, s.registry.clientURL)
|
machines := s.registry.ClientURLs(s.peerServer.Leader(), s.name)
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
w.Write([]byte(strings.Join(machines, ", ")))
|
w.Write([]byte(strings.Join(machines, ", ")))
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user