1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
use std::collections::HashMap;
use axum::{
RequestPartsExt,
extract::{FromRequestParts, Path},
http::{StatusCode, request::Parts},
response::{IntoResponse, Response},
};
use utoipa::ToSchema;
#[derive(Debug, ToSchema)]
pub enum Version {
V0,
}
impl<S> FromRequestParts<S> for Version
where
S: Send + Sync,
{
type Rejection = Response;
async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
let params: Path<HashMap<String, String>> =
parts.extract().await.map_err(IntoResponse::into_response)?;
let version = params
.get("version")
.ok_or_else(|| (StatusCode::NOT_FOUND, "version param missing").into_response())?;
match version.as_str() {
"v0" => Ok(Version::V0),
_ => Err((StatusCode::NOT_FOUND, "unknown version").into_response()),
}
}
}
|