first commit
This commit is contained in:
+17
@@ -0,0 +1,17 @@
|
||||
use axum::Router;
|
||||
use axum::routing::get;
|
||||
|
||||
use crate::env;
|
||||
|
||||
pub async fn start_api(config: env::EnvConfig) -> anyhow::Result<()> {
|
||||
let app = Router::new().route("/", get(root));
|
||||
let listerner = tokio::net::TcpListener::bind(format!("0.0.0.0:{}", config.http_port)).await?;
|
||||
|
||||
axum::serve(listerner, app)
|
||||
.await
|
||||
.map_err(|e| anyhow::anyhow!(e))
|
||||
}
|
||||
|
||||
async fn root() -> &'static str {
|
||||
"Hello, World!"
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
use dotenvy::dotenv;
|
||||
|
||||
pub struct EnvConfig {
|
||||
pub http_port: u16,
|
||||
pub bot_name: String,
|
||||
}
|
||||
|
||||
pub fn load_config() -> anyhow::Result<EnvConfig> {
|
||||
dotenv().ok();
|
||||
|
||||
let http_port = std::env::var("HTTP_PORT")?.parse()?;
|
||||
|
||||
let bot_name = std::env::var("BOT_NAME")?;
|
||||
|
||||
Ok(EnvConfig {
|
||||
http_port,
|
||||
bot_name,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
mod api;
|
||||
mod env;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let config = env::load_config()?;
|
||||
|
||||
api::start_api(config).await
|
||||
}
|
||||
Reference in New Issue
Block a user