-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor loading of environment variables for better maintainability …
…and error handling
- Loading branch information
1 parent
e18732b
commit f941995
Showing
4 changed files
with
42 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use std::env; | ||
use std::path::Path; | ||
|
||
pub fn load_environment_variables() { | ||
let path = ".env"; | ||
if Path::new(path).exists() { | ||
match dotenv::dotenv() { | ||
Ok(_) => {} | ||
Err(e) => println!("Failed to load {} file: {}", path, e), | ||
} | ||
} | ||
} | ||
|
||
pub fn get_env(key: &str, error_message: &str) -> String { | ||
match env::var(key) { | ||
Ok(val) => val, | ||
Err(_) => panic!("{}", error_message), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
mod conf; | ||
mod discord; | ||
pub use crate::discord::create_client; | ||
pub use crate::discord::Handler; | ||
pub use conf::get_env; | ||
pub use conf::load_environment_variables; |