aboutsummaryrefslogtreecommitdiff
path: root/src/consul.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2021-12-07 18:31:04 +0100
committerAlex Auvolat <alex@adnab.me>2021-12-07 18:31:04 +0100
commit9119c2f45c348497ea8d2f2f73768f50a198c4af (patch)
tree2f3c70f0c0377419efe2c3ed01c4162653114153 /src/consul.rs
parent489d364676003fa08130689a9f509de7d4df1602 (diff)
downloadtricot-9119c2f45c348497ea8d2f2f73768f50a198c4af.tar.gz
tricot-9119c2f45c348497ea8d2f2f73768f50a198c4af.zip
Use node IP when service IP is not available
Diffstat (limited to 'src/consul.rs')
-rw-r--r--src/consul.rs11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/consul.rs b/src/consul.rs
index 240c177..eb7aafd 100644
--- a/src/consul.rs
+++ b/src/consul.rs
@@ -9,13 +9,18 @@ use serde::{Deserialize, Serialize};
// ---- Watch and retrieve Consul catalog ----
//
#[derive(Serialize, Deserialize, Debug)]
-pub struct ConsulNodeListNode {
+pub struct ConsulNode {
#[serde(rename = "Node")]
pub node: String,
+ #[serde(rename = "Address")]
+ pub address: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct ConsulServiceEntry {
+ #[serde(rename = "Service")]
+ pub service: String,
+
#[serde(rename = "Address")]
pub address: String,
@@ -28,6 +33,8 @@ pub struct ConsulServiceEntry {
#[derive(Serialize, Deserialize, Debug)]
pub struct ConsulNodeCatalog {
+ #[serde(rename = "Node")]
+ pub node: ConsulNode,
#[serde(rename = "Services")]
pub services: HashMap<String, ConsulServiceEntry>,
}
@@ -84,7 +91,7 @@ impl Consul {
let url = format!("{}/v1/catalog/nodes", self.url);
let http = self.client.get(&url).send().await?;
- let resp: Vec<ConsulNodeListNode> = http.json().await?;
+ let resp: Vec<ConsulNode> = http.json().await?;
Ok(resp.into_iter().map(|n| n.node).collect::<Vec<_>>())
}