Spaces:
Sleeping
Sleeping
| pub mod error; | |
| pub mod health; | |
| pub mod config; | |
| pub mod userinfo; | |
| use config::ConfigData; | |
| use serde::Serialize; | |
| pub enum ApiStatus { | |
| Healthy, | |
| Success, | |
| Error, | |
| Failed, | |
| } | |
| // #[derive(Serialize)] | |
| // #[serde(untagged)] | |
| // pub enum ApiResponse { | |
| // HealthCheck(HealthCheckResponse), | |
| // ConfigData(NormalResponse<ConfigData>), | |
| // Error(ErrorResponse), | |
| // } | |
| // impl ApiResponse { | |
| // pub fn to_string(&self) -> String { | |
| // serde_json::to_string(self).unwrap() | |
| // } | |
| // } | |
| pub struct NormalResponse<T> { | |
| pub status: ApiStatus, | |
| pub data: Option<T>, | |
| pub message: Option<String>, | |
| } | |
| impl std::fmt::Display for NormalResponse<ConfigData> { | |
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | |
| write!(f, "{}", serde_json::to_string(self).unwrap()) | |
| } | |
| } | |
| pub struct NormalResponseNoData { | |
| pub status: ApiStatus, | |
| pub message: Option<String>, | |
| } | |
| pub struct ErrorResponse { | |
| // status -> 成功 / 失败 | |
| pub status: ApiStatus, | |
| // HTTP 请求的状态码 | |
| pub code: Option<u16>, | |
| // HTTP 请求的错误码 | |
| pub error: Option<String>, | |
| // 错误详情 | |
| pub message: Option<String>, | |
| } | |