refactor: reorganize reqwest client creation and load_config function
This commit is contained in:
+21
-22
@@ -56,15 +56,6 @@ use tracing_subscriber::{
|
||||
layer::SubscriberExt as _, util::SubscriberInitExt as _,
|
||||
};
|
||||
|
||||
fn create_reqwest_client() -> reqwest::Result<reqwest::Client> {
|
||||
reqwest::Client::builder()
|
||||
.user_agent(config::USER_AGENT)
|
||||
.timeout(tokio::time::Duration::from_secs(60))
|
||||
.connect_timeout(tokio::time::Duration::from_secs(5))
|
||||
.use_rustls_tls()
|
||||
.build()
|
||||
}
|
||||
|
||||
fn create_logging_filter(
|
||||
config: &config::Config,
|
||||
) -> tracing_subscriber::filter::Targets {
|
||||
@@ -90,6 +81,27 @@ fn create_logging_filter(
|
||||
}
|
||||
}
|
||||
|
||||
fn create_reqwest_client() -> reqwest::Result<reqwest::Client> {
|
||||
reqwest::Client::builder()
|
||||
.user_agent(config::USER_AGENT)
|
||||
.timeout(tokio::time::Duration::from_secs(60))
|
||||
.connect_timeout(tokio::time::Duration::from_secs(5))
|
||||
.use_rustls_tls()
|
||||
.build()
|
||||
}
|
||||
async fn load_config() -> color_eyre::Result<Arc<config::Config>> {
|
||||
let raw_config_path = raw_config::get_config_path();
|
||||
let raw_config = raw_config::read_config(Path::new(&raw_config_path))
|
||||
.await
|
||||
.wrap_err_with(move || format!("failed to read {raw_config_path}"))?;
|
||||
|
||||
let config = config::Config::from_raw_config(raw_config)
|
||||
.await
|
||||
.wrap_err("failed to create Config from RawConfig")?;
|
||||
|
||||
Ok(Arc::new(config))
|
||||
}
|
||||
|
||||
async fn download_output_dependencies(
|
||||
config: &config::Config,
|
||||
http_client: reqwest::Client,
|
||||
@@ -272,19 +284,6 @@ async fn run_without_tui(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn load_config() -> color_eyre::Result<Arc<config::Config>> {
|
||||
let raw_config_path = raw_config::get_config_path();
|
||||
let raw_config = raw_config::read_config(Path::new(&raw_config_path))
|
||||
.await
|
||||
.wrap_err_with(move || format!("failed to read {raw_config_path}"))?;
|
||||
|
||||
let config = config::Config::from_raw_config(raw_config)
|
||||
.await
|
||||
.wrap_err("failed to create Config from RawConfig")?;
|
||||
|
||||
Ok(Arc::new(config))
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> color_eyre::Result<()> {
|
||||
color_eyre::install().wrap_err("failed to install color_eyre hooks")?;
|
||||
|
||||
Reference in New Issue
Block a user