aboutsummaryrefslogtreecommitdiff
path: root/src/consul.rs
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2020-05-21 23:04:21 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2020-05-21 23:04:21 +0200
commit2a6b440270dc5d9b18061b69f8f700793d1ad0eb (patch)
tree5a6576fd9fd0080a982db5bec0629623b11f548c /src/consul.rs
parent8c43611eb5bbaeb42f19da8d8ed521df208bfada (diff)
downloaddiplonat-2a6b440270dc5d9b18061b69f8f700793d1ad0eb.tar.gz
diplonat-2a6b440270dc5d9b18061b69f8f700793d1ad0eb.zip
Working Consul
Diffstat (limited to 'src/consul.rs')
-rw-r--r--src/consul.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/consul.rs b/src/consul.rs
index e69de29..e438605 100644
--- a/src/consul.rs
+++ b/src/consul.rs
@@ -0,0 +1,33 @@
+use serde::{Serialize, Deserialize};
+use std::collections::HashMap;
+use anyhow::Result;
+
+#[derive(Serialize, Deserialize, Debug)]
+pub struct ServiceEntry {
+ Tags: Vec<String>
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+pub struct CatalogNode {
+ Services: HashMap<String, ServiceEntry>
+}
+
+pub struct Consul {
+ client: reqwest::Client,
+ url: String
+}
+
+impl Consul {
+ pub fn new(url: &str) -> Self {
+ return Self {
+ client: reqwest::Client::new(),
+ url: url.to_string()
+ };
+ }
+
+ pub async fn catalog_node(&self, host: &str) -> Result<CatalogNode> {
+ let url = format!("{}/v1/catalog/node/{}", self.url, host);
+ let resp: CatalogNode = self.client.get(&url).send().await?.json().await?;
+ return Ok(resp)
+ }
+}