init
This commit is contained in:
13
backend/src/response.rs
Normal file
13
backend/src/response.rs
Normal file
@ -0,0 +1,13 @@
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct ApiResponse<T> {
|
||||
pub code: i32,
|
||||
pub message: String,
|
||||
pub data: Option<T>,
|
||||
}
|
||||
|
||||
impl<T> ApiResponse<T> {
|
||||
pub fn ok(data: T) -> Self { Self { code: 0, message: "ok".into(), data: Some(data) } }
|
||||
pub fn err(code: i32, message: impl Into<String>) -> Self { Self { code, message: message.into(), data: None } }
|
||||
}
|
||||
Reference in New Issue
Block a user