You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
793 B
37 lines
793 B
3 years ago
|
use envy::{from_env, Result as EnvResult};
|
||
|
use serde::{de::DeserializeOwned, Deserialize};
|
||
|
|
||
|
#[derive(Deserialize)]
|
||
|
pub struct NoneEnv;
|
||
|
|
||
|
#[derive(Deserialize)]
|
||
|
pub struct Env<E = NoneEnv> {
|
||
|
#[serde(default = "default_host")]
|
||
|
pub u_server: String,
|
||
|
pub inner: E,
|
||
|
}
|
||
|
|
||
|
impl Env {
|
||
|
pub fn init_default() -> EnvResult<Self> {
|
||
|
let envs = [".env", ".env.private"];
|
||
|
for envfile in &envs {
|
||
|
dotenv::from_filename(envfile).ok();
|
||
|
}
|
||
|
from_env()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl<E: DeserializeOwned> Env<E> {
|
||
|
pub fn init() -> EnvResult<Self> {
|
||
|
let envs = [".env", ".env.private"];
|
||
|
for envfile in &envs {
|
||
|
dotenv::from_filename(envfile).ok();
|
||
|
}
|
||
|
from_env()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn default_host() -> String {
|
||
|
"ortem.xyz".to_string()
|
||
|
}
|