feat: add simple health check
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
15
crates/churn-server/Cargo.toml
Normal file
15
crates/churn-server/Cargo.toml
Normal file
@@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "churn-server"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
tokio.workspace = true
|
||||
tracing.workspace = true
|
||||
tracing-subscriber.workspace = true
|
||||
clap.workspace = true
|
||||
dotenv.workspace = true
|
||||
axum.workspace = true
|
64
crates/churn-server/src/main.rs
Normal file
64
crates/churn-server/src/main.rs
Normal file
@@ -0,0 +1,64 @@
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use axum::response::IntoResponse;
|
||||
use axum::routing::{get, post};
|
||||
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().nest(
|
||||
"/agent",
|
||||
Router::new()
|
||||
.route("/enroll", post(enroll))
|
||||
.route("/ping", post(ping))
|
||||
.route("/events", post(get_tasks)),
|
||||
);
|
||||
|
||||
tracing::info!("listening on {}", host);
|
||||
axum::Server::bind(&host)
|
||||
.serve(app.into_make_service())
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn enroll() -> impl IntoResponse {
|
||||
todo!()
|
||||
}
|
||||
|
||||
async fn ping() -> impl IntoResponse {
|
||||
todo!()
|
||||
}
|
||||
|
||||
async fn get_tasks() -> impl IntoResponse {
|
||||
todo!()
|
||||
}
|
Reference in New Issue
Block a user