From ff02e2cce239dd81fa8e86646a85e0a78880333d Mon Sep 17 00:00:00 2001 From: Jan Keith Darunday Date: Thu, 3 Aug 2023 09:03:25 +0800 Subject: [PATCH] Add dotenv support --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/app/config.rs | 3 +++ src/main.rs | 1 + 4 files changed, 12 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index c7722e2..4c7ed53 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -205,6 +205,7 @@ dependencies = [ "actix-web", "config", "diesel", + "dotenv", "lazy_static", "r2d2", "serde", @@ -573,6 +574,12 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257" +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + [[package]] name = "encoding_rs" version = "0.8.32" diff --git a/Cargo.toml b/Cargo.toml index 4e046ba..de7a505 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ serde_json = "1.0.104" actix-rt = "2.8.0" config = "0.13.3" lazy_static = "1.4.0" +dotenv = "0.15.0" [dependencies.diesel] features = ["postgres", "r2d2"] diff --git a/src/app/config.rs b/src/app/config.rs index 91e9be3..15abcef 100644 --- a/src/app/config.rs +++ b/src/app/config.rs @@ -1,4 +1,5 @@ use config::Config; +use dotenv::dotenv; lazy_static! { pub static ref CONFIG: Config = Config::builder() @@ -9,5 +10,7 @@ lazy_static! { } pub fn get<'a, T: serde::Deserialize<'a>>(key: &str) -> T { + dotenv().ok(); + CONFIG.get::(key).unwrap() } diff --git a/src/main.rs b/src/main.rs index a176468..0932337 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,7 @@ extern crate serde; #[macro_use] extern crate lazy_static; extern crate config; +extern crate dotenv; use actix_web::web::Data; use actix_web::{middleware, App, HttpServer};