Refactor project structure and add singlethreaded feature

Signed-off-by: trivernis <trivernis@protonmail.com>
main
trivernis 3 years ago
parent a15a713a0c
commit 40496b1686
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -27,4 +27,8 @@ features = ["derive"]
[dependencies.tokio]
version = "1.9.0"
features = ["macros", "rt-multi-thread", "process"]
features = ["macros", "process"]
[features]
default = ["tokio/rt-multi-thread"]
singlethreaded = ["tokio/rt"]

@ -1,17 +1,29 @@
use crate::logging::init_logger;
use crate::server::HookServer;
use crate::settings::get_settings;
#[cfg(all(feature = "singlethreaded", feature = "multithreaded"))]
compile_error!("Can't have singlethreaded and mutithreaded feature enabled at the same time.");
use std::path::{Path, PathBuf};
mod action;
mod command_template;
mod error;
mod logging;
use utils::logging::init_logger;
use utils::settings::get_settings;
use crate::server::HookServer;
mod server;
mod settings;
pub(crate) mod utils;
#[cfg(not(feature = "singlethreaded"))]
#[tokio::main]
async fn main() {
init_and_start().await
}
#[cfg(feature = "singlethreaded")]
#[tokio::main(flavor = "current_thread")]
async fn main() {
init_and_start().await
}
async fn init_and_start() {
init_logger();
let data_dir = dirs::data_dir()
.map(|d| d.join("multihook"))
@ -21,8 +33,9 @@ async fn main() {
}
let settings = get_settings();
let mut server = HookServer::new();
for (name, endpoint) in &settings.endpoints {
log::info!("Adding endpoint {} with path {}", name, &endpoint.path);
log::info!("Adding endpoint '{}' with path '{}'", name, &endpoint.path);
server.add_hook(endpoint.path.clone(), endpoint.action.clone().into())
}

@ -1,5 +1,5 @@
use crate::command_template::CommandTemplate;
use crate::error::MultihookResult;
use crate::server::command_template::CommandTemplate;
use crate::utils::error::MultihookResult;
use serde_json::Value;
use std::fs::read_to_string;
use std::path::PathBuf;

@ -1,12 +1,18 @@
use crate::action::HookAction;
use crate::error::MultihookError;
use std::collections::HashMap;
use std::net::SocketAddr;
use std::sync::Arc;
use warp::http::Response;
use warp::hyper::body::Bytes;
use warp::{Filter, Rejection};
use action::HookAction;
use crate::utils::error::MultihookError;
mod action;
pub mod command_template;
pub struct HookServer {
endpoints: HashMap<String, HookAction>,
}

@ -0,0 +1,3 @@
pub mod error;
pub mod logging;
pub mod settings;

@ -1,4 +1,4 @@
use crate::error::MultihookResult;
use crate::utils::error::MultihookResult;
use config::File;
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
Loading…
Cancel
Save