25 lines
743 B
Rust
25 lines
743 B
Rust
use anyhow::Result;
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct Config {
|
|
pub listen_addr: String,
|
|
pub database_url: String,
|
|
pub data_dir: String,
|
|
pub max_connections: u32,
|
|
}
|
|
|
|
impl Config {
|
|
pub fn from_env() -> Result<Self> {
|
|
Ok(Self {
|
|
listen_addr: std::env::var("LISTEN_ADDR").unwrap_or_else(|_| "127.0.0.1:8080".into()),
|
|
database_url: std::env::var("DATABASE_URL")
|
|
.unwrap_or_else(|_| "sqlite://openfut.db".into()),
|
|
data_dir: std::env::var("DATA_DIR").unwrap_or_else(|_| "data".into()),
|
|
max_connections: std::env::var("DB_MAX_CONNECTIONS")
|
|
.ok()
|
|
.and_then(|v| v.parse().ok())
|
|
.unwrap_or(5),
|
|
})
|
|
}
|
|
}
|