Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

how can i override config by .env and .env.dev .env.prod #65

Open
Silentdoer opened this issue Jan 22, 2022 · 3 comments
Open

how can i override config by .env and .env.dev .env.prod #65

Silentdoer opened this issue Jan 22, 2022 · 3 comments

Comments

@Silentdoer
Copy link

馃挕 Feature description

馃捇 Basic example

@arniu
Copy link

arniu commented Apr 26, 2022

Please load .env files by dotenv or dotenvy firstly, then parse the environments with envy.

@slvrtrn
Copy link

slvrtrn commented May 9, 2022

@Silentdoer that's how I implemented it in my project following the "Zero to production in Rust" book (it is recommended to use YAMLs there but I decided to do it my way): https://github.com/serge-klochkov/zero2prod/blob/main/src/config.rs#L24-L45

@rhrn
Copy link

rhrn commented Feb 22, 2023

@arniu you can do it manually, just load it first

use serde::Deserialize;

#[derive(Deserialize, Debug)]
pub struct Config {
  pub pg_db_url: String,
  pub mysql_db_url: String,
}

pub fn config() -> Result<Config, envy::Error> {
    dotenvy::dotenv().ok(); // !
    envy::from_env::<Config>()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants