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:
parent
a635f6b17c
commit
7565313290
@ -115,7 +115,7 @@ func (s *PeerServer) ListenAndServe(snapshot bool, cluster []string) {
|
||||
|
||||
} else {
|
||||
// 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++ {
|
||||
u, err := url.Parse(cluster[i])
|
||||
if err != nil {
|
||||
|
@ -111,8 +111,18 @@ func (r *Registry) peerURL(name string) (string, bool) {
|
||||
return "", false
|
||||
}
|
||||
|
||||
// Retrieves the URLs for all nodes using url function.
|
||||
func (r *Registry) URLs(leaderName, selfName string, url func(name string) (string, bool)) []string {
|
||||
// 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.
|
||||
func (r *Registry) urls(leaderName, selfName string, url func(name string) (string, bool)) []string {
|
||||
r.Lock()
|
||||
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.
|
||||
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.Write([]byte(strings.Join(machines, ", ")))
|
||||
return nil
|
||||
|
Loading…
x
Reference in New Issue
Block a user