diff options
Diffstat (limited to 'crates/api-core/src/health')
| -rw-r--r-- | crates/api-core/src/health/apidoc.rs | 12 | ||||
| -rw-r--r-- | crates/api-core/src/health/mod.rs | 27 |
2 files changed, 39 insertions, 0 deletions
diff --git a/crates/api-core/src/health/apidoc.rs b/crates/api-core/src/health/apidoc.rs new file mode 100644 index 0000000..45b8754 --- /dev/null +++ b/crates/api-core/src/health/apidoc.rs @@ -0,0 +1,12 @@ +use utoipa::OpenApi; + +use crate::Version; + +#[derive(OpenApi)] +#[openapi( + tags( + (name = "sellershut", description = "API health check"), + ), + components(schemas(Version)) +)] +pub struct ApiDocBase; diff --git a/crates/api-core/src/health/mod.rs b/crates/api-core/src/health/mod.rs new file mode 100644 index 0000000..a84dc85 --- /dev/null +++ b/crates/api-core/src/health/mod.rs @@ -0,0 +1,27 @@ +#[cfg(feature = "utoipa")] +mod apidoc; + +#[cfg(feature = "utoipa")] +pub use apidoc::*; + +#[derive(Default)] +pub struct BaseService; + +impl HealthDriver for BaseService {} + +pub trait HealthDriver: Send + Sync { + fn health(&self, app: &str, version: &str) -> String { + format!("{app} v{version} is live") + } +} + +#[cfg(test)] +mod tests { + use crate::health::{BaseService, HealthDriver}; + + #[test] + fn health() { + let app = BaseService.health(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")); + assert!(app.contains("is live")); + } +} |
