Introducing env catcher function

This commit is contained in:
Victor Mignot 2022-11-14 22:53:06 -05:00
parent 8df494c949
commit 10498b9b57
No known key found for this signature in database
GPG key ID: FFE4EF056FB5E0D0
3 changed files with 16 additions and 0 deletions

View file

15
src/environment.rs Normal file
View file

@ -0,0 +1,15 @@
//! Utility function to deal wit environment variable
use log::error;
use std::env;
/// Get the environment variiable var_name or panic
pub fn get_env_variable(var_name: &String) -> String {
match env::var(var_name) {
Ok(v) => v,
Err(_) => {
error!(target: "bot_warn_errors", "Failed to fetch the {} environment variable.", var_name);
panic!("Exiting...");
}
}
}

View file

@ -8,6 +8,7 @@
mod client; mod client;
mod database; mod database;
mod environment;
pub mod errors; pub mod errors;
pub use crate::{ pub use crate::{