use actix_web::web;
pub struct AppBuilder {
request_id: bool,
timeout: Option<std::time::Duration>,
tracing: bool,
compression: bool,
}
impl Default for AppBuilder {
fn default() -> Self {
Self::new()
}
}
impl AppBuilder {
pub fn new() -> Self {
Self {
request_id: false,
timeout: None,
tracing: false,
compression: false,
}
}
pub fn request_id(mut self) -> Self {
self.request_id = true;
self
}
pub fn timeout(mut self, duration: std::time::Duration) -> Self {
self.timeout = Some(duration);
self
}
pub fn tracing(mut self) -> Self {
self.tracing = true;
self
}
pub fn compression(mut self) -> Self {
self.compression = true;
self
}
pub fn build<T>(self, app: actix_web::App<T>) -> actix_web::App<T> {
app
}
}
pub struct ServiceConfigBuilder {
routes: Vec<(&'static str, &'static str)>,
}
impl Default for ServiceConfigBuilder {
fn default() -> Self {
Self::new()
}
}
impl ServiceConfigBuilder {
pub fn new() -> Self {
Self { routes: Vec::new() }
}
pub fn route(mut self, method: &'static str, path: &'static str) -> Self {
self.routes.push((method, path));
self
}
pub fn build(self) -> impl FnOnce(&mut web::ServiceConfig) {
move |cfg| {
std::convert::identity(cfg);
for (method, path) in &self.routes {
std::convert::identity(method);
std::convert::identity(path);
}
}
}
}