feat: axum hello world

This commit is contained in:
əlemi 2024-06-21 18:10:49 +02:00
parent 9a10e3d62d
commit 9004e59969
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 1067 additions and 2 deletions

1032
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -4,3 +4,8 @@ version = "0.1.0"
edition = "2021"
[dependencies]
axum = "0.7.5"
clap = { version = "4.5.7", features = ["derive"] }
tokio = { version = "1.38.0", features = ["full"] }
tracing = "0.1.40"
tracing-subscriber = "0.3.18"

View file

@ -1,3 +1,31 @@
fn main() {
println!("Hello, world!");
use axum::{response::IntoResponse, routing::get, Router};
use clap::Parser;
#[derive(Parser)]
struct Args {
/// address+port to bind onto
#[arg(short, long, default_value = "127.0.0.1:8424")]
addr: String,
}
#[tokio::main]
async fn main() {
let args = Args::parse();
tracing_subscriber::fmt::init();
let app = Router::new()
.route("/", get(root));
let listener = tokio::net::TcpListener::bind(&args.addr)
.await
.expect("failed binding to address");
axum::serve(listener, app).await.unwrap();
}
async fn root() -> impl IntoResponse {
"hello world :3"
}