Improve usability

This commit is contained in:
Pierre HUBERT 2024-08-19 15:24:52 +02:00
parent 663b6f285e
commit 05cde266a5
3 changed files with 8 additions and 4 deletions

1
Cargo.lock generated
View File

@ -666,6 +666,7 @@ dependencies = [
"actix-web", "actix-web",
"clap", "clap",
"env_logger", "env_logger",
"log",
] ]
[[package]] [[package]]

View File

@ -6,4 +6,5 @@ edition = "2021"
[dependencies] [dependencies]
clap = {version = "4.5.9", features = ["derive", "env"]} clap = {version = "4.5.9", features = ["derive", "env"]}
actix-web = "4" actix-web = "4"
env_logger = "0.11.5" env_logger = "0.11.5"
log = "0.4.22"

View File

@ -7,9 +7,9 @@ use env_logger::Env;
#[derive(clap::Parser, Debug)] #[derive(clap::Parser, Debug)]
#[command(version, about, long_about = None)] #[command(version, about, long_about = None)]
struct Args { struct Args {
/// Name of the person to greet /// Listen address
#[arg(env, short, long, default_value = "0.0.0.0:8000")] #[arg(env, short, long, default_value = "0.0.0.0:8000")]
listen_url: String, listen_addr: String,
} }
#[get("/")] #[get("/")]
@ -32,6 +32,8 @@ async fn main() -> std::io::Result<()> {
let args = Args::parse(); let args = Args::parse();
log::info!("Starting to listen on {}", args.listen_addr);
HttpServer::new(|| { HttpServer::new(|| {
App::new() App::new()
.wrap(Logger::default()) .wrap(Logger::default())
@ -39,7 +41,7 @@ async fn main() -> std::io::Result<()> {
.service(echo) .service(echo)
.route("/hey", web::get().to(manual_hello)) .route("/hey", web::get().to(manual_hello))
}) })
.bind(args.listen_url)? .bind(args.listen_addr)?
.run() .run()
.await .await
} }