Working Consul
This commit is contained in:
parent
8c43611eb5
commit
2a6b440270
5 changed files with 60 additions and 18 deletions
19
Cargo.lock
generated
19
Cargo.lock
generated
|
@ -131,6 +131,7 @@ dependencies = [
|
|||
"pretty_env_logger",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
|
@ -969,12 +970,26 @@ name = "serde"
|
|||
version = "1.0.107"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eba7550f2cdf88ffc23ab0f1607133486c390a8c0f89b57e589b9654ee15e04d"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.107"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "10be45e22e5597d4b88afcc71f9d7bfadcd604bf0c78a3ab4582b8d2b37f39f3"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.47"
|
||||
version = "1.0.53"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "15913895b61e0be854afd32fd4163fcd2a3df34142cf2cb961b310ce694cbf90"
|
||||
checksum = "993948e75b189211a9b31a7528f950c6adc21f9720b6438ff80a7fa2f864cea2"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
|
|
|
@ -13,5 +13,6 @@ log = "0.4"
|
|||
pretty_env_logger = "0.4"
|
||||
tokio = "0.2.11"
|
||||
futures = "0.3.5"
|
||||
serde = "1.0.107"
|
||||
serde = { version = "1.0.107", features = ["derive"] }
|
||||
serde_json = "1.0.53"
|
||||
anyhow = "1.0.28"
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
23
src/main.rs
23
src/main.rs
|
@ -1,31 +1,24 @@
|
|||
mod diplonat;
|
||||
mod node_state;
|
||||
mod environment_adapter;
|
||||
mod igd_adapter;
|
||||
mod consul;
|
||||
|
||||
//use std::net::SocketAddrV4;
|
||||
//use std::collections::HashMap;
|
||||
//use igd::PortMappingProtocol;
|
||||
use log::*;
|
||||
use node_state::*;
|
||||
use diplonat::*;
|
||||
use consul::*;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
pretty_env_logger::init();
|
||||
info!("Starting Diplonat");
|
||||
|
||||
/*
|
||||
let diplo = Diplonat::new().await.expect("Setup failed");
|
||||
diplo.listen().await.expect("A runtime error occured");
|
||||
/*
|
||||
let url = format!("http://127.0.0.1:8500/v1/catalog/node/{}", config.consul_node_name);
|
||||
let resp = reqwest::get(&url)
|
||||
.await
|
||||
.unwrap();
|
||||
//.json::<HashMap<String, String>>()
|
||||
//.await.unwrap();
|
||||
println!("{:#?}", resp);
|
||||
*/
|
||||
let c = Consul::new("http://127.0.0.1:8500");
|
||||
let cn = c.catalog_node("lheureduthe").await.expect("Failed to fetch API");
|
||||
println!("{:#?}", cn);
|
||||
|
||||
/*
|
||||
let gateway = match search_gateway(Default::default()).await {
|
||||
Ok(g) => g,
|
||||
Err(err) => return println!("Faild to find IGD: {}", err),
|
||||
|
|
0
src/messages.rs
Normal file
0
src/messages.rs
Normal file
Loading…
Reference in a new issue