Initial commit

This commit is contained in:
2024-08-02 16:10:24 +02:00
commit ec2977022d
4 changed files with 1571 additions and 0 deletions

45
src/main.rs Normal file
View File

@ -0,0 +1,45 @@
use actix_web::middleware::Logger;
use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder};
use clap::Parser;
use env_logger::Env;
/// Simple hello world HTTP server
#[derive(clap::Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
/// Name of the person to greet
#[arg(env, short, long, default_value = "0.0.0.0:8000")]
listen_url: String,
}
#[get("/")]
async fn hello() -> impl Responder {
HttpResponse::Ok().body("Hello world!")
}
#[post("/echo")]
async fn echo(req_body: String) -> impl Responder {
HttpResponse::Ok().body(req_body)
}
async fn manual_hello() -> impl Responder {
HttpResponse::Ok().body("Hey there!")
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
env_logger::init_from_env(Env::default().default_filter_or("info"));
let args = Args::parse();
HttpServer::new(|| {
App::new()
.wrap(Logger::default())
.service(hello)
.service(echo)
.route("/hey", web::get().to(manual_hello))
})
.bind(args.listen_url)?
.run()
.await
}