Implements Configuration via Env Variables
This commit is contained in:
22
src/config/config_server.rs
Normal file
22
src/config/config_server.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
use std::env;
|
||||
use cached::proc_macro::cached;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ConfigServer {
|
||||
pub(crate) host: String,
|
||||
pub(crate) port: u16,
|
||||
}
|
||||
|
||||
#[cached]
|
||||
pub fn get_config_server() -> ConfigServer {
|
||||
let h = option_env!("HOST")
|
||||
.unwrap_or("localhost").to_string();
|
||||
|
||||
let p = option_env!("PORT").unwrap_or("8500")
|
||||
.parse::<u16>().unwrap();
|
||||
|
||||
ConfigServer {
|
||||
host: h,
|
||||
port: p,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user