Implement path extractor (#124)

Fixes #42
This commit is contained in:
Sunli
2021-08-06 10:17:57 +02:00
committed by GitHub
parent 2be79168d8
commit 9fdbd42fba
14 changed files with 871 additions and 66 deletions
+4 -7
View File
@@ -8,7 +8,7 @@
use axum::{
async_trait,
extract::{extractor_middleware, ContentLengthLimit, Extension, RequestParts, UrlParams},
extract::{extractor_middleware, ContentLengthLimit, Extension, Path, RequestParts},
prelude::*,
response::IntoResponse,
routing::BoxRoute,
@@ -79,7 +79,7 @@ struct State {
}
async fn kv_get(
UrlParams((key,)): UrlParams<(String,)>,
Path(key): Path<String>,
Extension(state): Extension<SharedState>,
) -> Result<Bytes, StatusCode> {
let db = &state.read().unwrap().db;
@@ -92,7 +92,7 @@ async fn kv_get(
}
async fn kv_set(
UrlParams((key,)): UrlParams<(String,)>,
Path(key): Path<String>,
ContentLengthLimit(bytes): ContentLengthLimit<Bytes, { 1024 * 5_000 }>, // ~5mb
Extension(state): Extension<SharedState>,
) {
@@ -113,10 +113,7 @@ fn admin_routes() -> BoxRoute<hyper::Body> {
state.write().unwrap().db.clear();
}
async fn remove_key(
UrlParams((key,)): UrlParams<(String,)>,
Extension(state): Extension<SharedState>,
) {
async fn remove_key(Path(key): Path<String>, Extension(state): Extension<SharedState>) {
state.write().unwrap().db.remove(&key);
}