aboutsummaryrefslogtreecommitdiff
path: root/src/consul.rs
blob: e438605c20cc3a2c9808041e2c0c1cd540854a9f (plain) (blame)
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
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)
  }
}