summaryrefslogtreecommitdiff
path: root/src/client/connector
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-09-01 18:06:03 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-09-01 18:06:03 +0800
commite4a1fbbd596b5466b266a077cddd104933b4fbcf (patch)
treef5baa9e21d9b08c2d401428858505e09c3d1c396 /src/client/connector
init
Diffstat (limited to 'src/client/connector')
-rw-r--r--src/client/connector/connectors.rs5
-rw-r--r--src/client/connector/connectors/httpconnector.rs45
-rw-r--r--src/client/connector/manager.rs12
3 files changed, 62 insertions, 0 deletions
diff --git a/src/client/connector/connectors.rs b/src/client/connector/connectors.rs
new file mode 100644
index 0000000..3810a4a
--- /dev/null
+++ b/src/client/connector/connectors.rs
@@ -0,0 +1,5 @@
+mod httpconnector;
+
+pub(crate) enum Connectors<'a> {
+ Http(httpconnector::HTTPConnector<'a>),
+}
diff --git a/src/client/connector/connectors/httpconnector.rs b/src/client/connector/connectors/httpconnector.rs
new file mode 100644
index 0000000..97f79dd
--- /dev/null
+++ b/src/client/connector/connectors/httpconnector.rs
@@ -0,0 +1,45 @@
+use std::net::AddrParseError;
+
+use crate::connector::*;
+
+pub(crate) struct HTTPConnector<'a> {
+ prev: String,
+ url: &'a str,
+ channel: Channel<Self>,
+}
+
+impl<'a> HTTPConnector<'a> {
+ fn new(url: &'a str) -> Result<Self, AddrParseError> {
+ Ok(Self {
+ prev: String::new(),
+ url,
+ channel: Channel::new(),
+ })
+ }
+}
+
+impl Connection for HTTPConnector<'_> {
+ type Err = reqwest::Error;
+
+ fn test_connection(&self) -> std::result::Result<bool, reqwest::Error> {
+ Ok(true)
+ }
+
+ async fn update(&self) -> Option<Result<Self::Success, Self::Err>> {
+ let res = match reqwest::get(self.url).await {
+ Ok(resp) => match resp.text().await {
+ Ok(text) => text,
+ Err(e) => return Some(Err(e)),
+ },
+ Err(e) => return Some(Err(e)),
+ };
+
+ if res == self.prev {
+ return None;
+ }
+
+ _ = self.channel.sender.send(res.clone()); // don't care if receiver is dropped
+
+ Some(Ok(res))
+ }
+}
diff --git a/src/client/connector/manager.rs b/src/client/connector/manager.rs
new file mode 100644
index 0000000..9ca8a24
--- /dev/null
+++ b/src/client/connector/manager.rs
@@ -0,0 +1,12 @@
+use crate::connector::connectors;
+use std::thread;
+
+pub(crate) struct ConnectorManager<'a> {
+ connector: connectors::Connectors<'a>,
+}
+
+impl<'a> ConnectorManager<'a> {
+ pub(crate) fn new(connector: connectors::Connectors<'a>) -> Self {
+ Self { connector }
+ }
+}