Initial boilerplate scaffold for continuum-proxy
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
use std::env;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Config {
|
||||
pub gateway_id: String,
|
||||
pub farm_id: String,
|
||||
pub gateway_token: String,
|
||||
pub uplink_url: String,
|
||||
pub api_base: String,
|
||||
pub sqlite_path: String,
|
||||
pub go2rtc_bin: String,
|
||||
pub go2rtc_config: String,
|
||||
pub go2rtc_api_port: u16,
|
||||
pub discovery_interval_secs: u64,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn from_env() -> anyhow::Result<Self> {
|
||||
Ok(Self {
|
||||
gateway_id: require("CONTINUUM_GATEWAY_ID")?,
|
||||
farm_id: require("CONTINUUM_FARM_ID")?,
|
||||
gateway_token: require("CONTINUUM_GATEWAY_TOKEN")?,
|
||||
uplink_url: env_or("CONTINUUM_UPLINK_URL", "wss://api.continuum.local/ws/edge/v1"),
|
||||
api_base: env_or("CONTINUUM_API_BASE", "https://api.continuum.local"),
|
||||
sqlite_path: env_or("CONTINUUM_SQLITE_PATH", "./data/edge-cache.db"),
|
||||
go2rtc_bin: env_or("CONTINUUM_GO2RTC_BIN", "go2rtc"),
|
||||
go2rtc_config: env_or("CONTINUUM_GO2RTC_CONFIG", "./go2rtc.yaml"),
|
||||
go2rtc_api_port: env_or("CONTINUUM_GO2RTC_API_PORT", "1984").parse()?,
|
||||
discovery_interval_secs: env_or("CONTINUUM_DISCOVERY_INTERVAL_SECS", "30").parse()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn require(key: &str) -> anyhow::Result<String> {
|
||||
env::var(key).map_err(|_| anyhow::anyhow!("missing required env var {key}"))
|
||||
}
|
||||
|
||||
fn env_or(key: &str, default: &str) -> String {
|
||||
env::var(key).unwrap_or_else(|_| default.to_string())
|
||||
}
|
||||
Reference in New Issue
Block a user