aboutsummaryrefslogtreecommitdiff
path: root/src/api/admin/mod.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-05-13 14:30:30 +0200
committerAlex Auvolat <alex@adnab.me>2022-05-13 14:30:30 +0200
commitc0fb9fd0fe553e5eda39dcb1a09f059bcd631b6c (patch)
tree4d73c67a540e032190543fc319fad12c409e1e16 /src/api/admin/mod.rs
parent983037d965fdcdf089b09fa90fac31501defae9e (diff)
downloadgarage-c0fb9fd0fe553e5eda39dcb1a09f059bcd631b6c.tar.gz
garage-c0fb9fd0fe553e5eda39dcb1a09f059bcd631b6c.zip
Common error type and admin error type that uses it
Diffstat (limited to 'src/api/admin/mod.rs')
-rw-r--r--src/api/admin/mod.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/api/admin/mod.rs b/src/api/admin/mod.rs
index 05097c8b..68839039 100644
--- a/src/api/admin/mod.rs
+++ b/src/api/admin/mod.rs
@@ -1,6 +1,19 @@
pub mod api_server;
mod router;
+mod error;
mod bucket;
mod cluster;
mod key;
+
+
+use serde::{Deserialize};
+use hyper::{Request, Body};
+
+use error::*;
+
+pub async fn parse_json_body<T: for<'de> Deserialize<'de>>(req: Request<Body>) -> Result<T, Error> {
+ let body = hyper::body::to_bytes(req.into_body()).await?;
+ let resp: T = serde_json::from_slice(&body).ok_or_bad_request("Invalid JSON")?;
+ Ok(resp)
+}