1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use crate::option::QueryOptions;
use crate::{ClientError, Nomad};
use reqwest::Method;
pub struct Endpoint<'a> {
client: &'a Nomad,
}
impl<'a> Endpoint<'a> {
/// Create a new `Endpoint` with the given `Nomad` client to interact with
/// the status endpoints.
pub fn new(client: &'a Nomad) -> Self {
Self { client }
}
/// # Arguments
/// `opts`: Optional query options for the request.
///
/// # Returns
/// A `Result` containing the leader's address as a `String` or an error if
/// the request fails.
pub async fn get_leader(&self, opts: Option<QueryOptions>) -> Result<String, ClientError> {
let req = self.client.set_request_query_options(
self.client.build_request(Method::GET, "/v1/status/leader"),
&opts.unwrap_or_default(),
);
self.client.send_with_response::<String>(req).await
}
/// Get the list of peers in the Nomad cluster.
///
/// # Returns
/// A `Result` containing a vector of peer addresses as `String`s or an
/// error if the request fails.
pub async fn list_peers(&self) -> Result<Vec<String>, ClientError> {
let req = self.client.build_request(Method::GET, "/v1/status/peers");
self.client.send_with_response::<Vec<String>>(req).await
}
}