diff options
-rw-r--r-- | actix/src/main.rs | 52 | ||||
l--------- | debug_run | 1 |
2 files changed, 23 insertions, 30 deletions
diff --git a/actix/src/main.rs b/actix/src/main.rs index f11798f..51060ad 100644 --- a/actix/src/main.rs +++ b/actix/src/main.rs @@ -2,27 +2,29 @@ extern crate clap; -use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder}; +use actix_web::{get, App, HttpResponse, HttpServer, Responder}; -#[get("/")] -async fn hello() -> impl Responder { - HttpResponse::Ok().body("Hello world!") -} +#[actix_web::main] +async fn main() -> std::io::Result<()> { -#[post("/echo")] -async fn echo(req_body: String) -> impl Responder { - HttpResponse::Ok().body(req_body) -} + let cli_args = get_cli_args(); + let address = cli_args.value_of("address").unwrap(); + let port = cli_args.value_of("port").unwrap(); -async fn manual_hello() -> impl Responder { - HttpResponse::Ok().body("Hey there!") -} + println!("Binding to http://{}:{}", address, port); -#[actix_web::main] -async fn main() -> std::io::Result<()> { + HttpServer::new(|| { + App::new() + .service(index_handler) + }) + .bind(format!("{}:{}", address, port))? + .run() + .await +} - let arg_matches = clap::App::new("Actix Web Server") +fn get_cli_args() -> clap::ArgMatches<'static> { + clap::App::new("Actix Web Server") .about("Executable to run the web-template Web Server") .arg(clap::Arg::with_name("address") .help("The address to which the server binds") @@ -36,21 +38,11 @@ async fn main() -> std::io::Result<()> { .short("p") .takes_value(true) .default_value("8080")) - .get_matches(); - - let address = arg_matches.value_of("address").unwrap(); - let port = arg_matches.value_of("port").unwrap(); - - println!("Binding to {}:{}", address, port); + .get_matches() +} - HttpServer::new(|| { - App::new() - .service(hello) - .service(echo) - .route("/hey", web::get().to(manual_hello)) - }) - .bind(format!("{}:{}", address, port))? - .run() - .await +#[get("/")] +async fn index_handler() -> impl Responder { + HttpResponse::Ok().body("Hello world!") } diff --git a/debug_run b/debug_run new file mode 120000 index 0000000..17b102c --- /dev/null +++ b/debug_run @@ -0,0 +1 @@ +actix/target/debug/actix
\ No newline at end of file |