提交qiming-mcp-proxy

This commit is contained in:
Codex
2026-06-01 13:03:20 +08:00
parent 9e9486b7c2
commit afb3d9f4e6
394 changed files with 124494 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
use axum::{
Json,
response::{IntoResponse, Response},
};
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
/// 统一HTTP响应格式
#[derive(Debug, Serialize, Deserialize, ToSchema)]
pub struct HttpResult<T> {
pub code: String,
pub message: String,
pub data: Option<T>,
}
impl<T> HttpResult<T> {
/// 成功响应
pub fn success(data: T) -> Self {
Self {
code: "0000".to_string(),
message: "操作成功".to_string(),
data: Some(data),
}
}
/// 成功响应(自定义消息)
pub fn success_with_message(data: T, message: String) -> Self {
Self {
code: "0000".to_string(),
message,
data: Some(data),
}
}
/// 错误响应与泛型保持一致data为空
pub fn error<E>(code: String, message: String) -> HttpResult<E> {
HttpResult {
code,
message,
data: None,
}
}
/// 系统错误
pub fn system_error<E>(message: String) -> HttpResult<E> {
Self::error("E001".to_string(), message)
}
/// 格式不支持错误
pub fn unsupported_format<E>(message: String) -> HttpResult<E> {
Self::error("E002".to_string(), message)
}
/// 任务不存在错误
pub fn task_not_found<E>(message: String) -> HttpResult<E> {
Self::error("E003".to_string(), message)
}
/// 处理失败错误
pub fn processing_failed<E>(message: String) -> HttpResult<E> {
Self::error("E004".to_string(), message)
}
}
impl<T> IntoResponse for HttpResult<T>
where
T: serde::Serialize,
{
fn into_response(self) -> Response {
Json(self).into_response()
}
}