26 lines
632 B
Rust
26 lines
632 B
Rust
use std::path::PathBuf;
|
|
|
|
pub struct Config {
|
|
pub bind_addr: String,
|
|
/// Path to a DESI data file (JSON) to serve; `None` falls back to the
|
|
/// built-in placeholder catalogs.
|
|
pub desi_data: Option<PathBuf>,
|
|
}
|
|
|
|
impl Config {
|
|
pub fn from_env() -> anyhow::Result<Self> {
|
|
let bind_addr =
|
|
std::env::var("API_BIND_ADDR").unwrap_or_else(|_| "0.0.0.0:8080".to_string());
|
|
|
|
let desi_data = std::env::var("API_DESI_DATA")
|
|
.ok()
|
|
.filter(|s| !s.is_empty())
|
|
.map(PathBuf::from);
|
|
|
|
Ok(Self {
|
|
bind_addr,
|
|
desi_data,
|
|
})
|
|
}
|
|
}
|