diff options
Diffstat (limited to 'src/service/tcp.rs')
-rw-r--r-- | src/service/tcp.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/service/tcp.rs b/src/service/tcp.rs new file mode 100644 index 0000000..5f55091 --- /dev/null +++ b/src/service/tcp.rs @@ -0,0 +1,28 @@ +use std::fmt::Display; + +use serde::Deserialize; + +use crate::{Check, Error, Status}; + +#[derive(Debug, Clone, Deserialize)] +pub struct Tcp { + pub address: String, +} + +impl Display for Tcp { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "tcp://{}", self.address) + } +} + +impl Tcp { + pub async fn check(&self) -> Result<Check, Error> { + Ok(std::net::TcpStream::connect(&self.address) + .err() + .map(|err| Check { + status: Status::Fail, + output: Some(format!("error: {err}")), + }) + .unwrap_or_default()) + } +} |