use std::collections::HashMap; use std::net::SocketAddr; use std::sync::Arc; use axum::response::IntoResponse; use axum::routing::{get, post}; use axum::{async_trait, Router}; use clap::{Parser, Subcommand}; use tokio::sync::Mutex; #[derive(Parser)] #[command(author, version, about, long_about = None, subcommand_required = true)] struct Command { #[command(subcommand)] command: Option, } #[derive(Subcommand)] enum Commands { Serve { #[arg(env = "SERVICE_HOST", long, default_value = "127.0.0.1:3000")] host: SocketAddr, }, } struct AgentService(Arc); impl Default for AgentService { fn default() -> Self { Self(Arc::new(DefaultAgentService::default())) } } struct DefaultAgentService { agents: Arc>>, } impl Default for DefaultAgentService { fn default() -> Self { Self { agents: Arc::default(), } } } #[async_trait] impl AgentServiceTrait for DefaultAgentService { async fn enroll(&self, agent: Agent) -> anyhow::Result { todo!() } } #[async_trait] trait AgentServiceTrait { async fn enroll(&self, agent: Agent) -> anyhow::Result; } struct Agent { pub name: String, } struct AppState {} #[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 churn server"); let app = Router::new() .route("/ping", get(ping)) .nest( "/agent", Router::new() .route("/enroll", post(enroll)) .route("/ping", post(agent_ping)) .route("/events", post(get_tasks)), ) .with_state(); tracing::info!("churn server listening on {}", host); axum::Server::bind(&host) .serve(app.into_make_service()) .await .unwrap(); } None => {} } Ok(()) } async fn enroll() -> impl IntoResponse { todo!() } async fn agent_ping() -> impl IntoResponse { todo!() } async fn get_tasks() -> impl IntoResponse { todo!() } async fn ping() -> impl IntoResponse { "pong!" }