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 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
consul = "0.3.0" reqwest = { version = "0.10", features = ["json"] }
igd = { version = "0.10.0", features = ["aio"] } igd = { version = "0.10.0", features = ["aio"] }
tokio = "0.2.11" tokio = "0.2.11"

View file

@ -1,5 +1,7 @@
#!/bin/bash #!/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_PRIVATE_IP=10.3.3.37
export DIPLONAT_REFRESH_TIME=60 export DIPLONAT_REFRESH_TIME=60
export DIPLONAT_EXPIRATION_TIME=180 export DIPLONAT_EXPIRATION_TIME=180

View file

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