mehcode / config-rs

⚙️ Layered configuration system for Rust applications (with strong support for 12-factor applications).
Apache License 2.0
2.43k stars 206 forks source link

Environment struct not loading .env file #448

Closed dev-davexoyinbo closed 11 months ago

dev-davexoyinbo commented 11 months ago

Using the Environment struct doesn't load environment variables in .env file

let mut environment_data: HashMap<String, String> = Config::builder()
            .add_source(Environment::default())
            .build()?.try_deserialize()?;
log::error!("Environment Data: {:?}", environment_data);

Or is there a way to only load the .env file?

matthiasbeyer commented 11 months ago

This crate does not feature functionality to load .env files, just as it does not feature functionality to interpolate environment variables (which I answered in https://github.com/mehcode/config-rs/issues/447#issuecomment-1666865128 already).

Also, such functionality is not planned. Use a crate like handlebars to interpolate into your configuration files! For reading .env files, I don't know whether there's a crate for that out there (I never used .env files myself, so I don't even know what format it uses).

dev-davexoyinbo commented 11 months ago

Yes, thank you. I used handlebars and it now works

https://github.com/mehcode/config-rs/issues/447#issuecomment-1666885398