feat: added automatic runtime env variable existence checker
Build and Deploy / build-docker (push) Successful in 5m0s
Details
Build and Deploy / build-docker (push) Successful in 5m0s
Details
This commit is contained in:
parent
31b3e97676
commit
5928f5b0b5
30
src/main.rs
30
src/main.rs
|
@ -16,22 +16,26 @@ async fn main() -> Result<()> {
|
||||||
|
|
||||||
let port: u16 = 8080;
|
let port: u16 = 8080;
|
||||||
|
|
||||||
let pool = PgPool::connect(&std::env::var("DATABASE_URL").map_err(|_| {
|
check_envs(vec![
|
||||||
anyhow::Error::msg("Environment variable DATABASE_URL needs to be specified!")
|
"DATABASE_URL",
|
||||||
})?)
|
"SMTP_PASSWORD",
|
||||||
.await?;
|
"SMTP_HOST_URL",
|
||||||
|
"SMTP_USER",
|
||||||
|
"SMTP_PASSWORD",
|
||||||
|
])?;
|
||||||
|
|
||||||
let _ = &std::env::var("SMTP_HOST_URL").map_err(|_| {
|
let pool = PgPool::connect(&std::env::var("DATABASE_URL").unwrap()).await?;
|
||||||
anyhow::Error::msg("Environment variable SMTP_HOST_URL needs to be specified!")
|
|
||||||
})?;
|
|
||||||
let _ = &std::env::var("SMTP_USER").map_err(|_| {
|
|
||||||
anyhow::Error::msg("Environment variable SMTP_HOST_URL needs to be specified!")
|
|
||||||
})?;
|
|
||||||
let _ = &std::env::var("SMTP_PASSWORD").map_err(|_| {
|
|
||||||
anyhow::Error::msg("Environment variable SMTP_HOST_URL needs to be specified!")
|
|
||||||
})?;
|
|
||||||
|
|
||||||
api::start(port, pool).await?;
|
api::start(port, pool).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn check_envs(envs: Vec<&str>) -> Result<()> {
|
||||||
|
for env in envs {
|
||||||
|
let _ = &std::env::var(env).map_err(|_| {
|
||||||
|
anyhow::Error::msg(format!("Environment variable {env} needs to be set!"))
|
||||||
|
})?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue