chore: use gen env var optional
This commit is contained in:
parent
eb818a4282
commit
53c98c8bd6
|
|
@ -139,3 +139,6 @@ APPFLOWY_INDEXER_REDIS_URL=redis://redis:6379
|
|||
# AppFlowy Collaborate
|
||||
APPFLOWY_COLLABORATE_MULTI_THREAD=false
|
||||
APPFLOWY_COLLABORATE_REMOVE_BATCH_SIZE=100
|
||||
|
||||
# AppFlowy Web
|
||||
APPFLOWY_WEB_URL=
|
||||
|
|
|
|||
3
dev.env
3
dev.env
|
|
@ -125,3 +125,6 @@ APPFLOWY_INDEXER_REDIS_URL=redis://redis:6379
|
|||
# AppFlowy Collaborate
|
||||
APPFLOWY_COLLABORATE_MULTI_THREAD=false
|
||||
APPFLOWY_COLLABORATE_REMOVE_BATCH_SIZE=100
|
||||
|
||||
# AppFlowy Web
|
||||
APPFLOWY_WEB_URL=
|
||||
|
|
|
|||
|
|
@ -8,3 +8,21 @@ pub fn get_env_var(key: &str, default: &str) -> String {
|
|||
default.to_owned()
|
||||
})
|
||||
}
|
||||
|
||||
/// Optionally get an environment variable.
|
||||
/// if value is empty, return None.
|
||||
pub fn get_env_var_opt(key: &str) -> Option<String> {
|
||||
match std::env::var(key) {
|
||||
Ok(val) => {
|
||||
if val.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(val)
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
tracing::warn!("failed to read environment variable: {}, None set", e);
|
||||
None
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use semver::Version;
|
|||
use serde::Deserialize;
|
||||
use sqlx::postgres::{PgConnectOptions, PgSslMode};
|
||||
|
||||
use infra::env_util::get_env_var;
|
||||
use infra::env_util::{get_env_var, get_env_var_opt};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Config {
|
||||
|
|
@ -245,7 +245,7 @@ pub fn get_configuration() -> Result<Config, anyhow::Error> {
|
|||
client_id: get_env_var("APPFLOWY_APPLE_OAUTH_CLIENT_ID", ""),
|
||||
client_secret: get_env_var("APPFLOWY_APPLE_OAUTH_CLIENT_SECRET", "").into(),
|
||||
},
|
||||
appflowy_web_url: std::env::var("APPFLOWY_WEB_URL").ok(),
|
||||
appflowy_web_url: get_env_var_opt("APPFLOWY_WEB_URL"),
|
||||
};
|
||||
Ok(config)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue