Refactor code for apply/revert, implement Update/Apply/RevertLayout

This commit is contained in:
Alex Auvolat
2022-05-06 17:14:09 +02:00
parent 01c4876fb4
commit dd54d0b2b1
13 changed files with 179 additions and 63 deletions
+8
View File
@@ -1,4 +1,6 @@
use hyper::{Body, Request};
use idna::domain_to_unicode;
use serde::Deserialize;
use garage_util::data::*;
@@ -163,6 +165,12 @@ pub fn key_after_prefix(pfx: &str) -> Option<String> {
None
}
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)
}
#[cfg(test)]
mod tests {
use super::*;