consul lib does not work for us, switching to reqwest

This commit is contained in:
Quentin 2020-02-14 10:46:39 +01:00
parent f827fd3113
commit fdffe91397
4 changed files with 202 additions and 740 deletions

922
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -7,6 +7,6 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
consul = "0.3.0"
reqwest = { version = "0.10", features = ["json"] }
igd = { version = "0.10.0", features = ["aio"] }
tokio = "0.2.11"

View File

@ -1,5 +1,7 @@
#!/bin/bash
# http://127.0.0.1:8500/v1/catalog/node/rincevent?index=0
# then look at X-Consul-Index
export DIPLONAT_PRIVATE_IP=10.3.3.37
export DIPLONAT_REFRESH_TIME=60
export DIPLONAT_EXPIRATION_TIME=180

View File

@ -4,8 +4,7 @@ use std::net::SocketAddrV4;
use igd::aio::search_gateway;
use igd::PortMappingProtocol;
use consul::catalog::Catalog;
use consul::{Client, Config};
use std::collections::HashMap;
struct DiplonatConfig {
private_ip: String,
@ -58,13 +57,12 @@ async fn main() {
Err(e) => return println!("unable to build configuration: {}", e),
};
let consul_config = Config::new().unwrap();
let consul_client = Client::new(consul_config);
match consul_client.nodes(None) {
Ok(v) => println!("ok: {:?}", v),
Err(err) => println!("err: {}", err),
};
let resp = reqwest::get("http://127.0.0.1:5000")
.await
.unwrap()
.json::<HashMap<String, String>>()
.await.unwrap();
println!("{:#?}", resp);
let gateway = match search_gateway(Default::default()).await {
Ok(g) => g,