Skip to content

Commit

Permalink
exit if config fails to load
Browse files Browse the repository at this point in the history
  • Loading branch information
arshsingh committed Oct 21, 2023
1 parent 79173d1 commit 3fa5c12
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use figment::{
};
use futures::future::join_all;
use serde::Deserialize;
use tracing::error;

#[derive(Deserialize, Clone)]
pub struct Config {
Expand Down Expand Up @@ -67,13 +66,7 @@ impl Config {
let config = join_all(config_files.into_iter().map(load_json_config))
.await
.iter()
.fold(Figment::new(), |config, json| match json {
Ok(value) => config.merge(value),
Err(e) => {
error!("Failed to load config: {}", e);
config
}
})
.fold(Figment::new(), |config, json| config.merge(json))
.merge(Env::raw().split("__"))
.extract()?;

Expand Down Expand Up @@ -109,22 +102,24 @@ impl Config {
}
}

async fn load_json_config(url: String) -> Result<Data<Json>> {
async fn load_json_config(url: String) -> Data<Json> {
let data = match &url[..7] {
"http://" | "https:/" => {
let client = reqwest::Client::new();
let res = client
.get(&url)
.timeout(Duration::from_secs(10))
.send()
.await?
.await
.unwrap()
.text()
.await?;
.await
.unwrap();

Json::string(&res)
}
_ => Json::file(url),
};

Ok(data)
data
}

0 comments on commit 3fa5c12

Please sign in to comment.