-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4e5cc32
commit 52d4a5e
Showing
5 changed files
with
184 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use clap::Parser; | ||
|
||
/// Simple program to greet a person | ||
#[derive(Parser, Debug)] | ||
#[command(author, version, about, long_about = None)] | ||
struct Args { | ||
/// Name of the person to greet | ||
#[arg(short, long)] | ||
name: String, | ||
|
||
/// Number of times to greet | ||
#[arg(short, long, default_value_t = 1)] | ||
count: u8, | ||
} | ||
|
||
pub fn run() { | ||
let args = Args::parse(); | ||
|
||
for _ in 0..args.count { | ||
println!("Hello {}!", args.name) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,20 @@ | ||
use actix_web::{web, App, HttpServer}; | ||
use routes::{create_test, get_test}; | ||
use simple_logger::SimpleLogger; | ||
|
||
mod benchmark; | ||
mod cli; | ||
mod database; | ||
mod routes; | ||
mod utils; | ||
|
||
mod routes; | ||
mod web; | ||
|
||
#[tokio::main(flavor = "multi_thread")] | ||
async fn main() -> std::io::Result<()> { | ||
match SimpleLogger::new() | ||
.with_level(log::LevelFilter::Info) | ||
.init() | ||
{ | ||
Err(err) => { | ||
println!("failed to setup logging: {:?}", err); | ||
cfg_if::cfg_if! { | ||
if #[cfg(target_feature = "cli")] { | ||
cli::run(); | ||
}else { | ||
web::run_web_app().await; | ||
} | ||
_ => {} | ||
} | ||
|
||
let connection = match database::setup().await { | ||
Ok(c) => c, | ||
Err(err) => panic!("failed to setup database: {:?}", err), | ||
}; | ||
|
||
HttpServer::new(move || { | ||
App::new() | ||
.service(get_test) | ||
.service(create_test) | ||
.app_data(web::Data::new(connection.clone())) | ||
}) | ||
.bind(("0.0.0.0", 3000))? | ||
.run() | ||
.await | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use crate::database; | ||
use crate::routes::{create_test, get_test}; | ||
use actix_web::{web, App, HttpServer}; | ||
use simple_logger::SimpleLogger; | ||
|
||
pub async fn run_web_app() { | ||
match SimpleLogger::new() | ||
.with_level(log::LevelFilter::Info) | ||
.init() | ||
{ | ||
Err(err) => { | ||
println!("failed to setup logging: {:?}", err); | ||
} | ||
_ => {} | ||
} | ||
|
||
let connection = match database::setup().await { | ||
Ok(c) => c, | ||
Err(err) => panic!("failed to setup database: {:?}", err), | ||
}; | ||
|
||
let server = match HttpServer::new(move || { | ||
App::new() | ||
.service(get_test) | ||
.service(create_test) | ||
.app_data(web::Data::new(connection.clone())) | ||
}) | ||
.bind(("0.0.0.0", 3000)) | ||
{ | ||
Ok(s) => s, | ||
Err(err) => panic!("failed to create server: {:?}", err), | ||
}; | ||
|
||
server.run().await.unwrap(); | ||
} |