dotenv-rs / dotenv

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

Add default value macro #61

Open jharrilim opened 4 years ago

jharrilim commented 4 years ago

This PR adds an alternative macro, dotenv_or_default, which will provide a default value if the environment variable does not exist.

Example:

#[macro_use]
extern crate dotenv_codegen;

use actix_web::{
    App,
    HttpServer,
};

#[actix_rt::main]
pub async fn main() -> std::io::Result<()> {
  let hostname = dotenv_or_default!("HOSTNAME", "127.0.0.1");
  let port = dotenv_or_default!("PORT", "8080");
  let url = format!("{}:{}", hostname, port);
  let server = HttpServer::new(|| { App::new() })
    .bind(url)?
    .run()
    .await
}
codecov[bot] commented 4 years ago

Codecov Report

Merging #61 into master will decrease coverage by 5.06%. The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #61      +/-   ##
==========================================
- Coverage   86.77%   81.71%   -5.07%     
==========================================
  Files           7        7              
  Lines         242      257      +15     
==========================================
  Hits          210      210              
- Misses         32       47      +15     
Impacted Files Coverage Δ
dotenv_codegen_implementation/src/lib.rs 0.00% <0.00%> (ø)
dotenv/src/find.rs 90.90% <0.00%> (+3.95%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 3c1a77b...2dc9272. Read the comment docs.