2013-12-09 23:29:20 +00:00
|
|
|
package consul
|
|
|
|
|
|
|
|
// Status endpoint is used to check on server status
|
|
|
|
type Status struct {
|
|
|
|
server *Server
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ping is used to just check for connectivity
|
|
|
|
func (s *Status) Ping(args struct{}, reply *struct{}) error {
|
|
|
|
return nil
|
|
|
|
}
|
2013-12-10 23:16:41 +00:00
|
|
|
|
|
|
|
// Leader is used to get the address of the leader
|
|
|
|
func (s *Status) Leader(args struct{}, reply *string) error {
|
2016-07-28 19:11:28 +00:00
|
|
|
leader := string(s.server.raft.Leader())
|
2015-05-08 18:35:12 +00:00
|
|
|
if leader != "" {
|
|
|
|
*reply = leader
|
2013-12-10 23:16:41 +00:00
|
|
|
} else {
|
|
|
|
*reply = ""
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2013-12-23 19:39:29 +00:00
|
|
|
|
|
|
|
// Peers is used to get all the Raft peers
|
|
|
|
func (s *Status) Peers(args struct{}, reply *[]string) error {
|
2016-07-28 19:11:28 +00:00
|
|
|
future := s.server.raft.GetConfiguration()
|
|
|
|
if err := future.Error(); err != nil {
|
2013-12-23 19:39:29 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-07-28 19:11:28 +00:00
|
|
|
for _, server := range future.Configuration().Servers {
|
|
|
|
*reply = append(*reply, string(server.Address))
|
|
|
|
}
|
2013-12-23 19:39:29 +00:00
|
|
|
return nil
|
|
|
|
}
|