use serde::Deserialize; use crate::Status; pub mod command; pub mod http; pub mod tcp; pub trait IntoService { fn into_service( self, tx: tokio::sync::watch::Sender, ) -> impl std::future::Future; } pub fn default_interval() -> std::time::Duration { std::time::Duration::from_secs(5) } #[derive(Debug, Clone, Deserialize)] pub struct ServiceConfig { pub name: String, #[serde(flatten)] pub kind: ServiceKind, } #[derive(Debug, Clone, Deserialize)] #[serde(rename_all = "lowercase")] #[serde(tag = "kind")] pub enum ServiceKind { Http(http::Http), Tcp(tcp::Tcp), Exec(command::Command), } impl IntoService for ServiceKind { async fn into_service(self, tx: tokio::sync::watch::Sender) { match self { ServiceKind::Http(h) => h.into_service(tx).await, ServiceKind::Tcp(t) => t.into_service(tx).await, ServiceKind::Exec(c) => c.into_service(tx).await, } } }