use envy::{from_env, prefixed, Result as EnvResult}; use lazy_static::lazy_static; use serde::Deserialize; use uuid::Uuid; pub use envy::Error; pub const MASTER_PORT: u16 = 63714; lazy_static! { static ref UID: Uuid = Uuid::new_v4(); } #[inline] pub fn get_self_uid() -> Uuid { *UID } #[derive(Deserialize)] pub struct EndpointsEnv { #[serde(default = "default_host")] pub u_server: String, } impl EndpointsEnv { pub fn load() -> EndpointsEnv { dot(); from_env().unwrap() } } #[derive(Deserialize)] pub struct DBEnv { pub database: String, pub host: String, pub user: String, pub password: String, pub port: u16, } impl DBEnv { pub fn load() -> EnvResult { dot(); prefixed("POSTGRES_").from_env() } } #[derive(Deserialize)] pub struct AccessEnv { pub admin_auth_token: String, #[serde(default = "default_host")] pub u_server: String, } impl AccessEnv { pub fn load() -> EnvResult { dot(); from_env() } } fn dot() { let envs = [".env", ".env.private"]; for envfile in &envs { dotenv::from_filename(envfile).ok(); } } pub fn default_host() -> String { "ortem.xyz".to_string() }