mirror of
https://github.com/DefectingCat/phthonus
synced 2025-07-15 16:41:32 +00:00
fix(axum): route response
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
use std::time::Duration;
|
||||
use std::{fmt::Display, time::Duration};
|
||||
|
||||
use axum::{
|
||||
body::Bytes,
|
||||
@ -69,3 +69,15 @@ pub fn logging_route(router: Router) -> Router {
|
||||
|
||||
router.layer(trace_layer)
|
||||
}
|
||||
|
||||
/// Format request latency and status message
|
||||
/// return a string
|
||||
fn format_latency(latency: Duration, status: impl Display) -> String {
|
||||
let micros = latency.as_micros();
|
||||
let millis = latency.as_millis();
|
||||
if micros >= 1000 {
|
||||
format!("{} {}ms", status, millis)
|
||||
} else {
|
||||
format!("{} {}μs", status, micros)
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,11 @@
|
||||
use std::{borrow::Cow, collections::HashMap, time::Duration};
|
||||
use std::{borrow::Cow, time::Duration};
|
||||
|
||||
use axum::{
|
||||
async_trait,
|
||||
extract::{FromRequestParts, Path},
|
||||
http::{request::Parts, StatusCode, Uri},
|
||||
http::{StatusCode, Uri},
|
||||
middleware,
|
||||
response::{IntoResponse, Response},
|
||||
routing::get,
|
||||
Json, RequestPartsExt, Router,
|
||||
Json, Router,
|
||||
};
|
||||
use serde::Serialize;
|
||||
use tower::ServiceBuilder;
|
||||
@ -21,6 +19,7 @@ use crate::{
|
||||
|
||||
pub mod json;
|
||||
pub mod text;
|
||||
pub mod user;
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct RouteResponse<T>
|
||||
@ -72,3 +71,8 @@ pub fn routes() -> Router {
|
||||
pub async fn hello() -> String {
|
||||
format!("hello {}", env!("CARGO_PKG_NAME"))
|
||||
}
|
||||
|
||||
pub async fn fallback(uri: Uri) -> impl IntoResponse {
|
||||
info!("route {} not found", uri);
|
||||
(StatusCode::NOT_FOUND, "Not found")
|
||||
}
|
||||
|
1
frameworks/Rust/axum/src/routes/user.rs
Normal file
1
frameworks/Rust/axum/src/routes/user.rs
Normal file
@ -0,0 +1 @@
|
||||
|
Reference in New Issue
Block a user