Open frederikhors opened 4 years ago
I've done this as a work around. This is only part of the table you've referenced.
fn load_environment_variables() {
let environment = env::var("RUST_ENV").unwrap_or_else(|_| "".to_string());
if environment == "development" {
dotenv::from_filename(".env.development").ok();
}
if environment == "test" {
dotenv::from_filename(".env.test").ok();
}
if environment == "production" {
dotenv::from_filename(".env.production").ok();
}
dotenv::dotenv().ok();
}
I've done this in one of my projects. (Not tested)
#[derive(Deserialize, Debug, Clone)]
pub struct Config {
auth_url: String,
client_id: String,
scope: String,
redirect_uri: String,
}
fn load_config() -> Result<Config, envy::Error> {
let profile = if cfg!(test) {
"test"
} else if cfg!(debug_assertions) {
"development"
} else {
"production"
};
dotenv::from_filename(format!(".env.{}.local", profile)).ok();
dotenv::from_filename(".env.local").ok();
dotenv::from_filename(format!(".env.{}", profile)).ok();
dotenv::dotenv().ok();
envy::from_env::<Config>()
}
I've also used envy -> https://github.com/softprops/envy
Nice workarounds! I was looking for this just now. But I wonder why this is not part of dotenv
core features?
Coming from https://github.com/bkeepers/dotenv, is there a way to use these files too: https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use?