2023-06-17 02:16:11 +02:00
|
|
|
use std::net::SocketAddr;
|
|
|
|
|
|
|
|
use axum::routing::get;
|
|
|
|
use axum::Router;
|
|
|
|
use clap::{Parser, Subcommand};
|
|
|
|
|
|
|
|
#[derive(Parser)]
|
|
|
|
#[command(author, version, about, long_about = None, subcommand_required = true)]
|
|
|
|
struct Command {
|
|
|
|
#[command(subcommand)]
|
|
|
|
command: Option<Commands>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subcommand)]
|
|
|
|
enum Commands {
|
|
|
|
Serve {
|
|
|
|
#[arg(env = "SERVICE_HOST", long, default_value = "127.0.0.1:3000")]
|
|
|
|
host: SocketAddr,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> anyhow::Result<()> {
|
|
|
|
dotenv::dotenv().ok();
|
|
|
|
tracing_subscriber::fmt::init();
|
|
|
|
|
|
|
|
let cli = Command::parse();
|
|
|
|
|
|
|
|
match cli.command {
|
|
|
|
Some(Commands::Serve { host }) => {
|
|
|
|
tracing::info!("Starting service");
|
|
|
|
|
|
|
|
let app = Router::new().route("/", get(root));
|
|
|
|
|
|
|
|
tracing::info!("listening on {}", host);
|
2023-12-23 13:39:28 +01:00
|
|
|
let listener = tokio::net::TcpListener::bind(host).await.unwrap();
|
|
|
|
axum::serve(listener, app.into_make_service())
|
2023-06-17 02:16:11 +02:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
None => {}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn root() -> &'static str {
|
2023-06-17 12:14:10 +02:00
|
|
|
"Hello, %%name%%!"
|
2023-06-17 02:16:11 +02:00
|
|
|
}
|