open-consul/consul/status_endpoint.go
2016-08-08 19:19:17 -07:00

36 lines
798 B
Go

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
}
// Leader is used to get the address of the leader
func (s *Status) Leader(args struct{}, reply *string) error {
leader := string(s.server.raft.Leader())
if leader != "" {
*reply = leader
} else {
*reply = ""
}
return nil
}
// Peers is used to get all the Raft peers
func (s *Status) Peers(args struct{}, reply *[]string) error {
future := s.server.raft.GetConfiguration()
if err := future.Error(); err != nil {
return err
}
for _, server := range future.Configuration().Servers {
*reply = append(*reply, string(server.Address))
}
return nil
}