use std::{sync::OnceLock, time::Instant};
use axum::{http::StatusCode, response::IntoResponse};
use axum_extra::json;
use crate::auth::BasicAuthFromRequest;
pub static START_TIME: OnceLock<Instant> = OnceLock::new();
pub fn init_start_time() {
let _ = START_TIME.get_or_init(Instant::now);
}
pub async fn live_check() -> impl IntoResponse {
let start = START_TIME.get().expect("start time not initialized");
let uptime = Instant::now().duration_since(*start);
(
StatusCode::OK,
json!({
"status": "ok",
"version": env!("CARGO_PKG_VERSION"),
"uptime": uptime.as_secs(),
"timestamp": chrono::Local::now().timestamp(),
}),
)
.into_response()
}
#[allow(dead_code)]
pub async fn ready_check(_auth: BasicAuthFromRequest) -> impl IntoResponse {
StatusCode::NOT_IMPLEMENTED
}