This repository has been archived by the owner on Mar 18, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add
/api/:realm/accounts/:since/active-since
- Loading branch information
Showing
6 changed files
with
72 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use poem::{Endpoint, Middleware, Request, Response, Result}; | ||
|
||
use crate::prelude::*; | ||
|
||
pub struct TimeItMiddleware; | ||
|
||
impl<E: Endpoint<Output = Response>> Middleware<E> for TimeItMiddleware { | ||
type Output = TimeItMiddlewareImpl<E>; | ||
|
||
fn transform(&self, ep: E) -> Self::Output { | ||
TimeItMiddlewareImpl { ep } | ||
} | ||
} | ||
|
||
pub struct TimeItMiddlewareImpl<E> { | ||
ep: E, | ||
} | ||
|
||
#[poem::async_trait] | ||
impl<E: Endpoint<Output = Response>> Endpoint for TimeItMiddlewareImpl<E> { | ||
type Output = Response; | ||
|
||
async fn call(&self, request: Request) -> Result<Self::Output> { | ||
let method = request.method().clone(); | ||
let uri = request.uri().clone(); | ||
let start_instant = Instant::now(); | ||
let response = self.ep.call(request).await; | ||
info!(elapsed = ?start_instant.elapsed(), ?method, ?uri); | ||
response | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters