Properly handle empty node catalog
This commit is contained in:
parent
b0af49c24c
commit
1922017831
3 changed files with 30 additions and 3 deletions
|
@ -2,7 +2,7 @@
|
||||||
name = "df-consul"
|
name = "df-consul"
|
||||||
description = "Deuxfleurs' async Rust bindings for (a subset of) the Consul HTTP API"
|
description = "Deuxfleurs' async Rust bindings for (a subset of) the Consul HTTP API"
|
||||||
authors = [ "Alex Auvolat <alex@adnab.me>" ]
|
authors = [ "Alex Auvolat <alex@adnab.me>" ]
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://git.deuxfleurs.fr/Deuxfleurs/df-consul"
|
repository = "https://git.deuxfleurs.fr/Deuxfleurs/df-consul"
|
||||||
|
@ -15,3 +15,6 @@ serde = { version = "1.0.149", features = ["derive"] }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
bytes = "1"
|
bytes = "1"
|
||||||
reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls-manual-roots" ] }
|
reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls-manual-roots" ] }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
tokio = { version = "1.22", features = ["rt", "rt-multi-thread", "macros"] }
|
||||||
|
|
24
examples/test.rs
Normal file
24
examples/test.rs
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
use df_consul::*;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
let config = ConsulConfig {
|
||||||
|
addr: "http://localhost:8500".into(),
|
||||||
|
ca_cert: None,
|
||||||
|
tls_skip_verify: false,
|
||||||
|
client_cert: None,
|
||||||
|
client_key: None,
|
||||||
|
};
|
||||||
|
|
||||||
|
let consul = Consul::new(config, "").unwrap();
|
||||||
|
|
||||||
|
println!("== LIST NODES ==");
|
||||||
|
let list_nodes = consul.list_nodes().await.unwrap();
|
||||||
|
println!("{:?}", list_nodes);
|
||||||
|
|
||||||
|
println!("== CATALOG 1 ==");
|
||||||
|
println!("{:?}", consul.watch_node("caribou", None).await.unwrap());
|
||||||
|
|
||||||
|
println!("== CATALOG 2 ==");
|
||||||
|
println!("{:?}", consul.watch_node("cariacou", None).await.unwrap());
|
||||||
|
}
|
|
@ -146,7 +146,7 @@ impl Consul {
|
||||||
&self,
|
&self,
|
||||||
host: &str,
|
host: &str,
|
||||||
idx: Option<usize>,
|
idx: Option<usize>,
|
||||||
) -> Result<(ConsulNodeCatalog, usize)> {
|
) -> Result<(Option<ConsulNodeCatalog>, usize)> {
|
||||||
debug!("watch_node {} {:?}", host, idx);
|
debug!("watch_node {} {:?}", host, idx);
|
||||||
|
|
||||||
let url = match idx {
|
let url = match idx {
|
||||||
|
@ -160,7 +160,7 @@ impl Consul {
|
||||||
None => bail!("X-Consul-Index header not found"),
|
None => bail!("X-Consul-Index header not found"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let resp: ConsulNodeCatalog = http.json().await?;
|
let resp: Option<ConsulNodeCatalog> = http.json().await?;
|
||||||
Ok((resp, new_idx))
|
Ok((resp, new_idx))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue