feat: axum hello world
This commit is contained in:
parent
9a10e3d62d
commit
9004e59969
3 changed files with 1067 additions and 2 deletions
1032
Cargo.lock
generated
1032
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -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"
|
||||
|
|
32
src/main.rs
32
src/main.rs
|
@ -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"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue