use serde::Serialize;
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct ServerInfo {
pub version: String,
pub features: Vec<String>,
pub storage_backends: Vec<String>,
pub services: Vec<String>,
}
impl ServerInfo {
pub fn current() -> Self {
let mut features: Vec<String> = Vec::new();
if cfg!(feature = "postgres") {
features.push("postgres".to_string());
}
if cfg!(feature = "mysql") {
features.push("mysql".to_string());
}
if cfg!(feature = "jetstream-broker") {
features.push("jetstream-broker".to_string());
}
features.sort();
let mut storage_backends: Vec<String> = vec!["file".to_string(), "memory".to_string()];
if cfg!(feature = "storage-s3") || cfg!(feature = "storage-r2") {
storage_backends.push("s3".to_string());
}
if cfg!(feature = "storage-r2") {
storage_backends.push("r2".to_string());
}
if cfg!(feature = "storage-gcs") {
storage_backends.push("gs".to_string());
}
if cfg!(feature = "storage-azure") {
storage_backends.push("azure".to_string());
}
storage_backends.sort();
storage_backends.dedup();
Self {
version: env!("CARGO_PKG_VERSION").to_string(),
features,
storage_backends,
services: Vec::new(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn current_reports_version_and_always_present_backends() {
let info = ServerInfo::current();
assert_eq!(info.version, env!("CARGO_PKG_VERSION"));
assert!(info.storage_backends.contains(&"file".to_string()));
assert!(info.storage_backends.contains(&"memory".to_string()));
let mut sorted = info.storage_backends.clone();
sorted.sort();
sorted.dedup();
assert_eq!(info.storage_backends, sorted);
let mut feats = info.features.clone();
feats.sort();
feats.dedup();
assert_eq!(info.features, feats);
assert!(info.services.is_empty());
}
}