-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
32 lines (26 loc) · 945 Bytes
/
main.rs
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
use questdb_confstr::parse_conf_str;
pub fn ping_questdb(conf: &str) -> Result<(), String> {
let config =
parse_conf_str(conf).map_err(|e| format!("Failed to parse config string: {}", e))?;
let service = config.service();
if service != "http" && service != "https" {
return Err(format!("Unsupported service type: {}", service));
}
let addr = config
.get("addr")
.ok_or_else(|| "Missing 'addr' field in configuration".to_string())?;
let url = format!("{}://{}/ping", service, addr);
match ureq::get(&url).call() {
Ok(_response) => Ok(()),
Err(e) => return Err(e.to_string()),
}
}
fn main() {
let conf = std::env::args()
.nth(1)
.unwrap_or_else(|| "http::addr=localhost:9000;".to_string());
match ping_questdb(&conf) {
Ok(_) => println!("QuestDB is alive!"),
Err(e) => eprintln!("Failed to ping QuestDB: {}", e),
}
}