forked from 2sys/shoutdotdev
improve logging around config loading
This commit is contained in:
parent
c7fc56cff3
commit
e58e5002a0
3 changed files with 25 additions and 7 deletions
|
@ -6,6 +6,8 @@ AUTH.REDIRECT_URL=http://localhost:3000/auth/callback
|
||||||
AUTH.AUTH_URL=https://example.com/authorize
|
AUTH.AUTH_URL=https://example.com/authorize
|
||||||
AUTH.TOKEN_URL=https://example.com/token
|
AUTH.TOKEN_URL=https://example.com/token
|
||||||
AUTH.USERINFO_URL=https://example.com/userinfo
|
AUTH.USERINFO_URL=https://example.com/userinfo
|
||||||
|
# The .env parser (dotenvy) requires quotes around any value with spaces. Note
|
||||||
|
# that in this regard it is incompatible with Docker's --env-file parser.
|
||||||
EMAIL.VERIFICATION_FROM=no-reply@shout.dev
|
EMAIL.VERIFICATION_FROM=no-reply@shout.dev
|
||||||
EMAIL.MESSAGE_FROM=no-reply@shout.dev
|
EMAIL.MESSAGE_FROM=no-reply@shout.dev
|
||||||
EMAIL.SMTP.SERVER=smtp.example.com
|
EMAIL.SMTP.SERVER=smtp.example.com
|
||||||
|
|
|
@ -57,12 +57,12 @@ enum Commands {
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let settings = Settings::load().unwrap();
|
|
||||||
|
|
||||||
tracing_subscriber::fmt()
|
tracing_subscriber::fmt()
|
||||||
.with_env_filter(EnvFilter::from_default_env())
|
.with_env_filter(EnvFilter::from_default_env())
|
||||||
.init();
|
.init();
|
||||||
|
|
||||||
|
let settings = Settings::load().unwrap();
|
||||||
|
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
|
||||||
let database_url = settings.database_url.clone();
|
let database_url = settings.database_url.clone();
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use anyhow::{Context as _, Result};
|
||||||
use axum::extract::FromRef;
|
use axum::extract::FromRef;
|
||||||
use config::{Config, ConfigError, Environment};
|
use config::{Config, ConfigError, Environment};
|
||||||
use dotenvy::dotenv;
|
use dotenvy::dotenv;
|
||||||
|
@ -78,14 +79,29 @@ pub struct SlackSettings {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Settings {
|
impl Settings {
|
||||||
pub fn load() -> Result<Self, ConfigError> {
|
pub fn load() -> Result<Self> {
|
||||||
if let Err(err) = dotenv() {
|
match dotenv() {
|
||||||
tracing::warn!("Couldn't load .env file: {:?}", err);
|
Err(err) => {
|
||||||
|
if err.not_found() {
|
||||||
|
tracing::info!("no .env file found");
|
||||||
|
} else {
|
||||||
|
return Err(err).context("dotenvy error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(pathbuf) => {
|
||||||
|
tracing::info!(
|
||||||
|
"using env file {}",
|
||||||
|
pathbuf
|
||||||
|
.to_str()
|
||||||
|
.ok_or(anyhow::anyhow!("pathbuf is not valid unicode"))?
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let s = Config::builder()
|
let s = Config::builder()
|
||||||
.add_source(Environment::default())
|
.add_source(Environment::default())
|
||||||
.build()?;
|
.build()
|
||||||
s.try_deserialize()
|
.context("config error")?;
|
||||||
|
Ok(s.try_deserialize().context("deserialize error")?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue