summaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorToby Vincent <tobyv@tobyvin.dev>2024-09-28 00:54:46 -0500
committerToby Vincent <tobyv@tobyvin.dev>2024-09-28 00:58:45 -0500
commitcd774827dd14f68d8405c45d2d9da30b3fab050e (patch)
treea24e1cabb99170caa25edff53fc978111a1c9dd4 /src/lib.rs
parent04c7f7609e5bc3fadf95c53b37a9e6e12c4e539c (diff)
feat: refactor into pub-sub and impl SSE
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs36
1 files changed, 22 insertions, 14 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 1ccecf7..d24f635 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,22 +1,37 @@
-use std::path::PathBuf;
-
use serde::{Deserialize, Serialize};
-use service::Services;
-use tower_http::services::ServeDir;
+use service::ServiceHandles;
pub use crate::error::{Error, Result};
pub mod api;
pub mod error;
pub mod service;
+pub mod sse;
+
+pub fn router() -> axum::Router<ServiceHandles> {
+ axum::Router::new()
+ .nest("/api", api::router())
+ .nest("/sse", sse::router())
+}
-#[derive(Debug, Clone, Default, Serialize, Deserialize)]
+#[derive(Debug, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(rename_all = "lowercase", tag = "status", content = "output")]
pub enum Status {
- #[default]
Pass,
- Fail(Option<String>),
Warn(Option<String>),
+ Fail(Option<String>),
+ #[default]
+ Unknown,
+}
+
+impl Status {
+ pub fn update(&mut self, status: Status) -> bool {
+ let modif = *self != status;
+ if modif {
+ *self = status;
+ }
+ modif
+ }
}
impl<T: std::error::Error> From<T> for Status {
@@ -30,10 +45,3 @@ impl axum::response::IntoResponse for Status {
axum::Json(self).into_response()
}
}
-
-pub fn router(root: PathBuf) -> axum::Router<Services> {
- axum::Router::new()
- .nest_service("/", ServeDir::new(root))
- .nest("/api", api::router())
- .layer(tower_http::trace::TraceLayer::new_for_http())
-}