dotenv-rs / dotenv

Library to help supply environment variables in testing and development
MIT License
557 stars 85 forks source link

Proposals to read a directory by default #59

Open bingryan opened 4 years ago

bingryan commented 4 years ago

I have a proposal to better coordinate the deployment of containers. When we are developing locally, one .env configuration file may be sufficient, but when containers are used, multiple configuration files are often required to be used together. For example, .envs/.mysql is to provide mysql deployment configure, and .envs/.redis is to provide redis configuration deployment configure。

use std::env;

fn main() {
    //  Read all configuration files in the following directory
    // .envs
    //     .envs/.elasticsearch
    //     .envs/.redis
    //     .envs/mysql
    //     .envs/mysql/.mysql2
    //     .envs/mysql/.mysql1

    use dotenv;
    dotenv::dotenvs().ok();
    for (key, value) in env::vars() {
        println!("{}: {}", key, value);
    }
}

In this way, I developed well with docker-compose.

I have implemented the logic, if it feels good, I will PR.