Use async/await syntax
This commit is contained in:
parent
253de8cea2
commit
81bb65db4e
26
src/main.rs
26
src/main.rs
@ -17,6 +17,9 @@ mod service;
|
|||||||
mod statics;
|
mod statics;
|
||||||
mod template;
|
mod template;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
cache::CacheState,
|
cache::CacheState,
|
||||||
error::{Error, Result},
|
error::{Error, Result},
|
||||||
@ -29,7 +32,6 @@ use actix_web::{
|
|||||||
middleware, web, App, HttpResponse, HttpServer,
|
middleware, web, App, HttpResponse, HttpServer,
|
||||||
};
|
};
|
||||||
use badge::{Badge, BadgeOptions};
|
use badge::{Badge, BadgeOptions};
|
||||||
use futures::future::Future;
|
|
||||||
use git2::Repository;
|
use git2::Repository;
|
||||||
use number_prefix::NumberPrefix;
|
use number_prefix::NumberPrefix;
|
||||||
use std::{
|
use std::{
|
||||||
@ -51,7 +53,8 @@ struct GeneratorForm<'a> {
|
|||||||
repo: Cow<'a, str>,
|
repo: Cow<'a, str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct State {
|
#[derive(Debug)]
|
||||||
|
pub(crate) struct State {
|
||||||
repos: String,
|
repos: String,
|
||||||
cache: String,
|
cache: String,
|
||||||
}
|
}
|
||||||
@ -176,6 +179,7 @@ where
|
|||||||
let service_path = format!("{}/{}", T::domain(), repo);
|
let service_path = format!("{}/{}", T::domain(), repo);
|
||||||
let path = format!("{}/{}", state.repos, service_path);
|
let path = format!("{}/{}", state.repos, service_path);
|
||||||
let url = format!("https://{}", service_path);
|
let url = format!("https://{}", service_path);
|
||||||
|
error!("{}", url);
|
||||||
let remote_exists = remote_exists(&url).await?;
|
let remote_exists = remote_exists(&url).await?;
|
||||||
let file = Path::new(&path);
|
let file = Path::new(&path);
|
||||||
if !file.exists() {
|
if !file.exists() {
|
||||||
@ -208,10 +212,10 @@ where
|
|||||||
mapper(res)
|
mapper(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn json_hoc<T: Service>(
|
pub(crate) async fn json_hoc<T: Service>(
|
||||||
state: web::Data<Arc<State>>,
|
state: web::Data<Arc<State>>,
|
||||||
data: web::Path<(String, String)>,
|
data: web::Path<(String, String)>,
|
||||||
) -> impl Future<Output = Result<HttpResponse>> {
|
) -> Result<HttpResponse> {
|
||||||
let mapper = |r| match r {
|
let mapper = |r| match r {
|
||||||
HocResult::NotFound => p404(),
|
HocResult::NotFound => p404(),
|
||||||
HocResult::Hoc {
|
HocResult::Hoc {
|
||||||
@ -222,13 +226,13 @@ fn json_hoc<T: Service>(
|
|||||||
commits,
|
commits,
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
handle_hoc_request::<T, _>(state, data, mapper)
|
handle_hoc_request::<T, _>(state, data, mapper).await
|
||||||
}
|
}
|
||||||
|
|
||||||
fn calculate_hoc<T: Service>(
|
pub(crate) async fn calculate_hoc<T: Service>(
|
||||||
state: web::Data<Arc<State>>,
|
state: web::Data<Arc<State>>,
|
||||||
data: web::Path<(String, String)>,
|
data: web::Path<(String, String)>,
|
||||||
) -> impl Future<Output = Result<HttpResponse>> {
|
) -> Result<HttpResponse> {
|
||||||
let mapper = move |r| match r {
|
let mapper = move |r| match r {
|
||||||
HocResult::NotFound => p404(),
|
HocResult::NotFound => p404(),
|
||||||
HocResult::Hoc { hoc_pretty, .. } => {
|
HocResult::Hoc { hoc_pretty, .. } => {
|
||||||
@ -254,13 +258,13 @@ fn calculate_hoc<T: Service>(
|
|||||||
.body(body))
|
.body(body))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
handle_hoc_request::<T, _>(state, data, mapper)
|
handle_hoc_request::<T, _>(state, data, mapper).await
|
||||||
}
|
}
|
||||||
|
|
||||||
fn overview<T: Service>(
|
async fn overview<T: Service>(
|
||||||
state: web::Data<Arc<State>>,
|
state: web::Data<Arc<State>>,
|
||||||
data: web::Path<(String, String)>,
|
data: web::Path<(String, String)>,
|
||||||
) -> impl Future<Output = Result<HttpResponse>> {
|
) -> Result<HttpResponse> {
|
||||||
let mapper = |r| match r {
|
let mapper = |r| match r {
|
||||||
HocResult::NotFound => p404(),
|
HocResult::NotFound => p404(),
|
||||||
HocResult::Hoc {
|
HocResult::Hoc {
|
||||||
@ -293,7 +297,7 @@ fn overview<T: Service>(
|
|||||||
Ok(HttpResponse::Ok().content_type("text/html").body(buf))
|
Ok(HttpResponse::Ok().content_type("text/html").body(buf))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
handle_hoc_request::<T, _>(state, data, mapper)
|
handle_hoc_request::<T, _>(state, data, mapper).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
|
Loading…
Reference in New Issue
Block a user