All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
51 lines
1.2 KiB
Rust
51 lines
1.2 KiB
Rust
use clap::{Parser, Subcommand};
|
|
use std::net::SocketAddr;
|
|
|
|
use crate::{
|
|
api::axum_serve,
|
|
app::{App, SharedApp},
|
|
grpc::tonic_serve,
|
|
};
|
|
|
|
#[derive(Parser)]
|
|
#[command(author, version, about, long_about = None, subcommand_required = true)]
|
|
pub struct Command {
|
|
#[command(subcommand)]
|
|
pub command: Option<Commands>,
|
|
}
|
|
|
|
#[derive(Subcommand)]
|
|
pub enum Commands {
|
|
Serve {
|
|
#[arg(env = "SERVICE_HOST", long, default_value = "127.0.0.1:3000")]
|
|
host: SocketAddr,
|
|
#[arg(env = "SERVICE_GRPC_HOST", long, default_value = "127.0.0.1:7900")]
|
|
grpc_host: SocketAddr,
|
|
},
|
|
}
|
|
|
|
impl Command {
|
|
pub async fn run() -> anyhow::Result<()> {
|
|
let cli = Command::parse();
|
|
|
|
if let Some(Commands::Serve { host, grpc_host }) = cli.command {
|
|
tracing_subscriber::fmt::init();
|
|
|
|
tracing::info!("Starting service");
|
|
|
|
let app = SharedApp::new(App::new().await?);
|
|
|
|
tokio::select! {
|
|
res = axum_serve(host, app.clone()) => {
|
|
res?;
|
|
},
|
|
res = tonic_serve(grpc_host, app.clone()) => {
|
|
res?;
|
|
},
|
|
};
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
}
|