aboutsummaryrefslogtreecommitdiff
path: root/src/consul.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/consul.rs')
-rw-r--r--src/consul.rs18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/consul.rs b/src/consul.rs
index 1bb30aa..1123996 100644
--- a/src/consul.rs
+++ b/src/consul.rs
@@ -1,21 +1,21 @@
-use serde::{Serialize, Deserialize};
+use anyhow::{anyhow, Result};
+use serde::{Deserialize, Serialize};
use std::collections::HashMap;
-use anyhow::{Result, anyhow};
#[derive(Serialize, Deserialize, Debug)]
pub struct ServiceEntry {
- pub Tags: Vec<String>
+ pub Tags: Vec<String>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct CatalogNode {
- pub Services: HashMap<String, ServiceEntry>
+ pub Services: HashMap<String, ServiceEntry>,
}
pub struct Consul {
client: reqwest::Client,
url: String,
- idx: Option<u64>
+ idx: Option<u64>,
}
impl Consul {
@@ -23,7 +23,7 @@ impl Consul {
return Self {
client: reqwest::Client::new(),
url: url.to_string(),
- idx: None
+ idx: None,
};
}
@@ -34,16 +34,16 @@ impl Consul {
pub async fn watch_node(&mut self, host: &str) -> Result<CatalogNode> {
let url = match self.idx {
Some(i) => format!("{}/v1/catalog/node/{}?index={}", self.url, host, i),
- None => format!("{}/v1/catalog/node/{}", self.url, host)
+ None => format!("{}/v1/catalog/node/{}", self.url, host),
};
let http = self.client.get(&url).send().await?;
self.idx = match http.headers().get("X-Consul-Index") {
Some(v) => Some(v.to_str()?.parse::<u64>()?),
- None => return Err(anyhow!("X-Consul-Index header not found"))
+ None => return Err(anyhow!("X-Consul-Index header not found")),
};
let resp: CatalogNode = http.json().await?;
- return Ok(resp)
+ return Ok(resp);
}
}