feat: add initial

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2026-02-03 20:58:24 +01:00
commit fcb04af9b8
14 changed files with 1531 additions and 0 deletions

1
crates/forge-enforce/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/target

View File

@@ -0,0 +1,17 @@
[package]
name = "forge-enforce"
version = "0.1.0"
edition = "2024"
[dependencies]
anyhow.workspace = true
tokio.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
clap.workspace = true
dotenv.workspace = true
axum.workspace = true
serde.workspace = true
uuid.workspace = true
tower-http.workspace = true
notmad.workspace = true

View File

@@ -0,0 +1,30 @@
use clap::{Parser, Subcommand};
use crate::{Config, State, cli::serve::ServeCommand};
mod serve;
#[derive(Parser)]
#[command(author, version, about, long_about = None, subcommand_required = true)]
struct Command {
#[command(subcommand)]
command: Option<Commands>,
#[command(flatten)]
config: Config,
}
#[derive(Subcommand)]
enum Commands {
Serve(ServeCommand),
}
pub async fn execute() -> anyhow::Result<()> {
let cli = Command::parse();
let state = State::new(cli.config).await?;
match cli.command.expect("a subcommand") {
Commands::Serve(cmd) => cmd.execute(&state).await,
}
}

View File

@@ -0,0 +1,49 @@
use std::net::SocketAddr;
use axum::{Router, extract::MatchedPath, http::Request, routing::get};
use tower_http::trace::TraceLayer;
use crate::State;
#[derive(clap::Parser)]
pub struct ServeCommand {
#[arg(env = "SERVICE_HOST", long, default_value = "127.0.0.1:3000")]
host: SocketAddr,
}
impl ServeCommand {
pub async fn execute(&self, state: &State) -> anyhow::Result<()> {
let app = Router::new()
.route("/", get(root))
.with_state(state.clone())
.layer(
TraceLayer::new_for_http().make_span_with(|request: &Request<_>| {
// Log the matched route's path (with placeholders not filled in).
// Use request.uri() or OriginalUri if you want the real path.
let matched_path = request
.extensions()
.get::<MatchedPath>()
.map(MatchedPath::as_str);
tracing::info_span!(
"http_request",
method = ?request.method(),
matched_path,
some_other_field = tracing::field::Empty,
)
}), // ...
);
tracing::info!("listening on {}", self.host);
let listener = tokio::net::TcpListener::bind(self.host).await.unwrap();
axum::serve(listener, app.into_make_service())
.await
.unwrap();
Ok(())
}
}
async fn root() -> &'static str {
"Hello, nostore!"
}

View File

@@ -0,0 +1,14 @@
mod state;
pub use state::*;
pub mod cli;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
dotenv::dotenv().ok();
tracing_subscriber::fmt::init();
cli::execute().await?;
Ok(())
}

View File

@@ -0,0 +1,13 @@
#[derive(clap::Parser, Clone)]
pub struct Config {}
#[derive(Clone)]
pub struct State {
pub config: Config,
}
impl State {
pub async fn new(config: Config) -> anyhow::Result<Self> {
Ok(Self { config })
}
}