From 7594193dddad8d77a45bdb3907864ff31baebadf Mon Sep 17 00:00:00 2001 From: William Luke Date: Wed, 29 Dec 2021 23:18:09 +0000 Subject: [PATCH] Cleanup to repo parsing --- src/deploy.rs | 8 ++++---- src/repoconf.rs | 10 ++-------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/deploy.rs b/src/deploy.rs index ad0b722..b781e23 100644 --- a/src/deploy.rs +++ b/src/deploy.rs @@ -5,10 +5,10 @@ use std::sync::Arc; use crate::repoconf::RepoConf; -pub async fn process(req: Request, _rc: Arc>) -> Result, hyper::Error> { +pub async fn process(req: Request, _rc: Arc>) -> Result, hyper::Error> { match (req.method(), req.uri().path()) { (&Method::GET, "/") | (&Method::GET, "/index.html") => Ok(Response::new(Body::from("Hello world\n"))), - (&Method::POST, "/deploy") => deploy(req).await, + (&Method::POST, "/deploy") => deploy(req, _rc).await, _ => { // Return 404 not found response. Ok(Response::builder() @@ -19,11 +19,11 @@ pub async fn process(req: Request, _rc: Arc>) -> Result) -> Result, hyper::Error> { +async fn deploy(req: Request, _rc: Arc>) -> Result, hyper::Error> { let bytes_stream = hyper::body::to_bytes(req).await?; let _data: HashMap = serde_json::from_slice(&bytes_stream).unwrap(); - let res = Response::builder().status(StatusCode::default()).body(Body::from("Done.\n")).unwrap(); + let res = Response::builder().status(StatusCode::default()).body(Body::empty()).unwrap(); Ok(res) } \ No newline at end of file diff --git a/src/repoconf.rs b/src/repoconf.rs index 98667f6..0bc38d8 100644 --- a/src/repoconf.rs +++ b/src/repoconf.rs @@ -1,5 +1,4 @@ use config::{Config, ConfigError, File}; -use std::vec::Vec; use std::collections::HashMap; #[derive(Serialize, Deserialize, Debug, Clone)] @@ -20,17 +19,12 @@ pub enum RepoConf { } impl RepoConf { - pub fn new() -> Result, ConfigError> { + pub fn new() -> Result, ConfigError> { let mut c = Config::default(); c.merge(File::with_name("config").format(config::FileFormat::Yaml))?; let repos = c.get::>("repos")?; - let mut v = Vec::::new(); - for (_, rc) in repos { - v.push(rc); - } - - return Ok(v); + Ok(repos) } } \ No newline at end of file -- 2.45.2