32 lines
947 B
Rust
32 lines
947 B
Rust
|
use log::{error, info, warn};
|
||
|
use url::Url;
|
||
|
use crate::config::load_config;
|
||
|
|
||
|
pub fn daemon_main(name: String, server: String) {
|
||
|
// Validate the `server`
|
||
|
info!("Checking server url...");
|
||
|
let api_base = match Url::parse(&server) {
|
||
|
Ok(u) => u,
|
||
|
Err(e) => {
|
||
|
error!("Invalid server url `{}`: {}", server, e);
|
||
|
std::process::exit(1);
|
||
|
}
|
||
|
};
|
||
|
match api_base.scheme() {
|
||
|
"http" => { warn!("HTTP api urls are not reccomended. Please switch to HTTPS if possible.") },
|
||
|
"https" => (),
|
||
|
_ => {
|
||
|
error!("Unsupported protocol `{}` (expected one of http, https)", api_base.scheme());
|
||
|
std::process::exit(1);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
info!("Loading config...");
|
||
|
let config = match load_config(&name) {
|
||
|
Ok(cfg) => cfg,
|
||
|
Err(e) => {
|
||
|
error!("Error loading configuration: {}", e);
|
||
|
std::process::exit(1);
|
||
|
}
|
||
|
};
|
||
|
}
|