This commit is contained in:
2026-05-22 08:13:06 +02:00
parent 3199f201a9
commit 01e72931d1
3 changed files with 69 additions and 5 deletions
+14
View File
@@ -1,9 +1,13 @@
use std::time::Duration;
pub struct Config {
pub token: String,
pub device_id: String,
pub base_url: String,
pub max_output_bytes: u64,
pub writer_channel_capacity: usize,
pub ping_interval: Duration,
pub ping_timeout: Duration,
}
impl Config {
@@ -11,6 +15,8 @@ impl Config {
const DEFAULT_DEVICE_ID: &str = "device";
const DEFAULT_MAX_OUTPUT_BYTES: u64 = 10 * 1024 * 1024;
const DEFAULT_WRITER_CHANNEL_CAPACITY: usize = 32;
const DEFAULT_PING_INTERVAL_SECS: u64 = 30;
const DEFAULT_PING_TIMEOUT_SECS: u64 = 10;
pub fn from_env() -> Result<Self, String> {
let token = std::env::var("TOKEN")
@@ -32,6 +38,14 @@ impl Config {
"WRITER_CHANNEL_CAPACITY",
Self::DEFAULT_WRITER_CHANNEL_CAPACITY,
),
ping_interval: Duration::from_secs(parse_env(
"PING_INTERVAL_SECS",
Self::DEFAULT_PING_INTERVAL_SECS,
)),
ping_timeout: Duration::from_secs(parse_env(
"PING_TIMEOUT_SECS",
Self::DEFAULT_PING_TIMEOUT_SECS,
)),
})
}
}