Replies: 4 comments 2 replies
-
这个跟中间件无关,你应该序列化数据,然后修改,再放入 body。 |
Beta Was this translation helpful? Give feedback.
0 replies
-
感谢答复! 还是想问一下,有办法通过 因为目前代码已实现很多,统一走的类似下方这种,想在在原有逻辑上变更也没有明确思路。 impl<T: ToSchema> ResObj<T> {
pub fn ok(data: Option<T>) -> Self {
Self {
code: 0,
msg: "ok".to_string(),
data,
}
}
pub fn custom_code(code: i32, msg: String) -> Self {
Self {
code,
msg,
data: None,
}
}
pub fn err(err: String) -> Self {
Self {
code: 500,
msg: err,
data: None,
}
}
}
#[allow(dead_code)]
pub fn res_json_ok<T: ToSchema>(data: Option<T>) -> Json<ResObj<T>> {
Json(ResObj::ok(data))
}
res.render(res_json_custom::<()>(404, "没有对应的接口".to_string())); |
Beta Was this translation helpful? Give feedback.
0 replies
-
我没很看懂你的代码。 但是肯定是可以再处理的。本身 request response 就是可写可读的对象, 你任何一个中间件想写就写,想去就去里面的数据。本身没问题, 只是可能你代码逻辑本身有问题。 |
Beta Was this translation helpful? Give feedback.
2 replies
-
想要实现的效果: {
"code": 0,
"msg": "ok"
} 增加中间件后的响应: {
"request_id": "01HHW89K6T39RQTRA5WFHNJ1PG",
"code": 0,
"msg": "ok"
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
中间件代码示例:
期望返回:
实际返回
求助应该怎么写才正确?
Beta Was this translation helpful? Give feedback.
All reactions