use serde::{Deserialize, Serialize};
use std::time::Duration;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DaemonConfig {
#[serde(default)]
pub auto_commit: bool,
#[serde(default)]
pub auto_push: bool,
#[serde(default)]
pub auto_pull: bool,
#[serde(default = "default_interval")]
pub interval_secs: u64,
#[serde(default = "default_timeout")]
pub timeout_secs: u64,
#[serde(default = "default_max_connections")]
pub max_connections: usize,
#[serde(default = "default_log_level")]
pub log_level: String,
#[serde(default)]
pub log_json: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub log_file: Option<String>,
}
impl Default for DaemonConfig {
fn default() -> Self {
Self {
auto_commit: false,
auto_push: false,
auto_pull: false,
interval_secs: default_interval(),
timeout_secs: default_timeout(),
max_connections: default_max_connections(),
log_level: default_log_level(),
log_json: false,
log_file: None,
}
}
}
impl DaemonConfig {
pub fn interval(&self) -> Duration {
Duration::from_secs(self.interval_secs)
}
pub fn timeout(&self) -> Duration {
Duration::from_secs(self.timeout_secs)
}
}
fn default_interval() -> u64 {
5
}
fn default_timeout() -> u64 {
30
}
fn default_max_connections() -> usize {
100
}
fn default_log_level() -> String {
"info".to_string()
}