Implements Configuration via Env Variables

This commit is contained in:
2024-02-25 00:21:49 -03:00
parent ff0739573d
commit 05dc487099
9 changed files with 235 additions and 18 deletions

17
src/config/config_auth.rs Normal file
View File

@@ -0,0 +1,17 @@
use std::env;
use cached::proc_macro::cached;
#[derive(Clone)]
pub struct ConfigAuth {
pub auth_url: String,
}
#[cached]
pub fn get_config_auth() -> ConfigAuth {
let url = env::var("AUTH_URL")
.expect("AUTH_URL must be set");
ConfigAuth {
auth_url: url,
}
}

View 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,
}
}

2
src/config/mod.rs Normal file
View File

@@ -0,0 +1,2 @@
pub mod config_server;
pub mod config_auth;