aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-04-23 18:27:51 +0000
committerFuwn <[email protected]>2021-04-23 18:27:51 +0000
commit70e6a577025651639c745f029fbeb36922438939 (patch)
tree354756327afab7744392752db12f421a0040e4f3 /src/main.rs
parentMerge branch 'tokio-re' of https://github.com/Whirlsplash/whirl into tokio-re (diff)
downloadwhirl-70e6a577025651639c745f029fbeb36922438939.tar.xz
whirl-70e6a577025651639c745f029fbeb36922438939.zip
major: :star:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs127
1 files changed, 72 insertions, 55 deletions
diff --git a/src/main.rs b/src/main.rs
index cb13cd7..22d72a6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,73 +1,90 @@
#[macro_use]
extern crate log;
-use whirl::server::auto::server::AutoServer;
use std::error::Error;
-use whirl::server::room::server::RoomServer;
-use whirl::config;
-use whirl::config::get_config;
+
use structopt::clap::Shell;
-use whirl::cli::cli;
+use whirl::{
+ cli::cli,
+ config,
+ config::get_config,
+ re_server::{
+ distributor::Distributor,
+ hub::Hub,
+ server::{
+ Server,
+ ServerType::{AutoServer, RoomServer},
+ },
+ },
+};
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
- // Setup CLI
- let matches = cli().get_matches();
+ // Setup CLI
+ let matches = cli().get_matches();
- // Set logging level
- let mut log_level = "whirl=error,whirl=warn,whirl=info".to_string();
- if matches.is_present("debug") { log_level += ",whirl=debug"; }
- if matches.is_present("trace") { log_level += ",whirl=trace"; }
- std::env::set_var("RUST_LOG", log_level);
+ // Set logging level
+ let mut log_level = "whirl=error,whirl=warn,whirl=info".to_string();
+ if matches.is_present("debug") {
+ log_level += ",whirl=debug";
+ }
+ if matches.is_present("trace") {
+ log_level += ",whirl=trace";
+ }
+ std::env::set_var("RUST_LOG", log_level);
- // Set database URL
- std::env::set_var("DATABASE_URL", "sqlite:whirl.db");
+ // Set database URL
+ std::env::set_var("DATABASE_URL", "sqlite:whirl.db");
- // Setup logging
- dotenv::dotenv().ok();
- pretty_env_logger::init();
+ // Setup logging
+ dotenv::dotenv().ok();
+ pretty_env_logger::init();
- // Handle CLI command
- if matches.is_present("run") {
- run().await.unwrap();
- } else if let Some(cmd) = matches.subcommand_matches("config") {
- if cmd.is_present("show") {
- println!("{:#?}", config::get_config());
- }
- } else if let Some(shell) = matches.subcommand_matches("completions") {
- if shell.is_present("powershell") {
- cli().gen_completions(env!("CARGO_PKG_NAME"), Shell::PowerShell, ".");
- } else if shell.is_present("bash") {
- cli().gen_completions(env!("CARGO_PKG_NAME"), Shell::Bash, ".");
- } else if shell.is_present("elvish") {
- cli().gen_completions(env!("CARGO_PKG_NAME"), Shell::Elvish, ".");
- } else if shell.is_present("zsh") {
- cli().gen_completions(env!("CARGO_PKG_NAME"), Shell::Zsh, ".");
- } else if shell.is_present("fish") {
- cli().gen_completions(env!("CARGO_PKG_NAME"), Shell::Fish, ".");
- }
- debug!("generated shell completions");
- }
+ // Handle CLI command
+ if matches.is_present("run") {
+ run().await.unwrap();
+ } else if let Some(cmd) = matches.subcommand_matches("config") {
+ if cmd.is_present("show") {
+ println!("{:#?}", config::get_config());
+ }
+ } else if let Some(shell) = matches.subcommand_matches("completions") {
+ if shell.is_present("powershell") {
+ cli().gen_completions(env!("CARGO_PKG_NAME"), Shell::PowerShell, ".");
+ } else if shell.is_present("bash") {
+ cli().gen_completions(env!("CARGO_PKG_NAME"), Shell::Bash, ".");
+ } else if shell.is_present("elvish") {
+ cli().gen_completions(env!("CARGO_PKG_NAME"), Shell::Elvish, ".");
+ } else if shell.is_present("zsh") {
+ cli().gen_completions(env!("CARGO_PKG_NAME"), Shell::Zsh, ".");
+ } else if shell.is_present("fish") {
+ cli().gen_completions(env!("CARGO_PKG_NAME"), Shell::Fish, ".");
+ }
+ debug!("generated shell completions");
+ }
- Ok(())
+ Ok(())
}
async fn run() -> Result<(), Box<dyn Error>> {
- let threads = vec![
- tokio::spawn(async move {
- let _ = AutoServer::listen(
- &*format!("0.0.0.0:{}", get_config().unwrap().auto_server_port)
- ).await;
- }),
- tokio::spawn(async move {
- let _ = RoomServer::listen(
- &*format!("0.0.0.0:{}", get_config().unwrap().room_server_port)
- ).await;
- }),
- ];
- for thread in threads {
- let _ = thread.await;
- }
+ let threads = vec![
+ tokio::spawn(async move {
+ let _ = Distributor::listen(
+ &*format!("0.0.0.0:{}", get_config().unwrap().distributor_port,),
+ AutoServer,
+ )
+ .await;
+ }),
+ tokio::spawn(async move {
+ let _ = Hub::listen(
+ &*format!("0.0.0.0:{}", get_config().unwrap().hub_port),
+ RoomServer,
+ )
+ .await;
+ }),
+ ];
+ for thread in threads {
+ let _ = thread.await;
+ }
- Ok(())
+ Ok(())
}