use actix_web::{web, get, HttpResponse, Responder}; use sqlx::postgres::PgPool; #[get("/health")] pub async fn health_check(pool: web::Data) -> impl Responder { // 检查数据库连接 match sqlx::query("SELECT 1").fetch_one(pool.get_ref()).await { Ok(_) => HttpResponse::Ok().json(serde_json::json!({ "status": "healthy", "database": "connected" })), Err(e) => { tracing::error!("健康检查失败: {}", e); HttpResponse::ServiceUnavailable().json(serde_json::json!({ "status": "unhealthy", "database": "disconnected", "error": "数据库连接失败" })) } } }