summaryrefslogtreecommitdiff
path: root/actix/src/main.rs
diff options
context:
space:
mode:
authorxengineering <mail2xengineering@protonmail.com>2021-03-01 20:12:02 +0100
committerxengineering <mail2xengineering@protonmail.com>2021-03-01 20:32:55 +0100
commit537b2828a4911eabb44c6b10d3f86ef00f6165da (patch)
tree702a2cf2353c33c99c2a546be8f29ed65110a18b /actix/src/main.rs
parent92ce74d92e5fe57e59cefcf454373c1a26022cf6 (diff)
downloadweb-template-537b2828a4911eabb44c6b10d3f86ef00f6165da.tar
web-template-537b2828a4911eabb44c6b10d3f86ef00f6165da.tar.zst
web-template-537b2828a4911eabb44c6b10d3f86ef00f6165da.zip
Implement CLI Parameters with clap
Diffstat (limited to 'actix/src/main.rs')
-rw-r--r--actix/src/main.rs28
1 files changed, 27 insertions, 1 deletions
diff --git a/actix/src/main.rs b/actix/src/main.rs
index 4f03d08..f11798f 100644
--- a/actix/src/main.rs
+++ b/actix/src/main.rs
@@ -1,6 +1,10 @@
+// vim: tabstop=4 shiftwidth=4 expandtab
+
+extern crate clap;
use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder};
+
#[get("/")]
async fn hello() -> impl Responder {
HttpResponse::Ok().body("Hello world!")
@@ -17,13 +21,35 @@ async fn manual_hello() -> impl Responder {
#[actix_web::main]
async fn main() -> std::io::Result<()> {
+
+ let arg_matches = 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")
+ .long("address")
+ .short("a")
+ .takes_value(true)
+ .default_value("127.0.0.1"))
+ .arg(clap::Arg::with_name("port")
+ .help("The port to which the server binds")
+ .long("port")
+ .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);
+
HttpServer::new(|| {
App::new()
.service(hello)
.service(echo)
.route("/hey", web::get().to(manual_hello))
})
- .bind("127.0.0.1:8080")?
+ .bind(format!("{}:{}", address, port))?
.run()
.await
}