@@ -1,9 +1,12 @@
|
||||
use std::collections::HashMap;
|
||||
use std::net::SocketAddr;
|
||||
use std::sync::Arc;
|
||||
|
||||
use axum::response::IntoResponse;
|
||||
use axum::routing::{get, post};
|
||||
use axum::Router;
|
||||
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)]
|
||||
@@ -20,6 +23,44 @@ enum Commands {
|
||||
},
|
||||
}
|
||||
|
||||
struct AgentService(Arc<dyn AgentServiceTrait + Send + Sync + 'static>);
|
||||
|
||||
impl Default for AgentService {
|
||||
fn default() -> Self {
|
||||
Self(Arc::new(DefaultAgentService::default()))
|
||||
}
|
||||
}
|
||||
|
||||
struct DefaultAgentService {
|
||||
agents: Arc<Mutex<HashMap<String, Agent>>>,
|
||||
}
|
||||
|
||||
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<String> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
trait AgentServiceTrait {
|
||||
async fn enroll(&self, agent: Agent) -> anyhow::Result<String>;
|
||||
}
|
||||
|
||||
struct Agent {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
struct AppState {}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
dotenv::dotenv().ok();
|
||||
@@ -29,17 +70,20 @@ async fn main() -> anyhow::Result<()> {
|
||||
|
||||
match cli.command {
|
||||
Some(Commands::Serve { host }) => {
|
||||
tracing::info!("Starting service");
|
||||
tracing::info!("Starting churn server");
|
||||
|
||||
let app = Router::new().nest(
|
||||
"/agent",
|
||||
Router::new()
|
||||
.route("/enroll", post(enroll))
|
||||
.route("/ping", post(ping))
|
||||
.route("/events", post(get_tasks)),
|
||||
);
|
||||
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!("listening on {}", host);
|
||||
tracing::info!("churn server listening on {}", host);
|
||||
axum::Server::bind(&host)
|
||||
.serve(app.into_make_service())
|
||||
.await
|
||||
@@ -55,10 +99,14 @@ async fn enroll() -> impl IntoResponse {
|
||||
todo!()
|
||||
}
|
||||
|
||||
async fn ping() -> impl IntoResponse {
|
||||
async fn agent_ping() -> impl IntoResponse {
|
||||
todo!()
|
||||
}
|
||||
|
||||
async fn get_tasks() -> impl IntoResponse {
|
||||
todo!()
|
||||
}
|
||||
|
||||
async fn ping() -> impl IntoResponse {
|
||||
"pong!"
|
||||
}
|
||||
|
Reference in New Issue
Block a user