| 1 |
use anyhow::{Context, Result}; |
| 2 |
use serde::Deserialize; |
| 3 |
use std::path::PathBuf; |
| 4 |
|
| 5 |
#[derive(Debug, Clone, Deserialize)] |
| 6 |
pub struct Config { |
| 7 |
pub listen: String, |
| 8 |
pub db_path: PathBuf, |
| 9 |
pub topology_path: PathBuf, |
| 10 |
|
| 11 |
pub workdir: PathBuf, |
| 12 |
|
| 13 |
pub release_root: PathBuf, |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#[serde(default)] |
| 18 |
pub scratch_db_url: Option<String>, |
| 19 |
} |
| 20 |
|
| 21 |
impl Config { |
| 22 |
pub fn load() -> Result<Self> { |
| 23 |
let path = std::env::var("SANDO_CONFIG").unwrap_or_else(|_| "sando-daemon.toml".into()); |
| 24 |
let raw = std::fs::read_to_string(&path) |
| 25 |
.with_context(|| format!("reading daemon config at {path}"))?; |
| 26 |
Ok(toml::from_str(&raw)?) |
| 27 |
} |
| 28 |
} |
| 29 |
|