33 lines
860 B
Rust
33 lines
860 B
Rust
mod api_response;
|
|
mod app;
|
|
mod config;
|
|
mod error_middleware;
|
|
mod health;
|
|
mod http_error;
|
|
mod logging;
|
|
mod request_context;
|
|
mod response_headers;
|
|
mod state;
|
|
|
|
use tokio::net::TcpListener;
|
|
use tracing::info;
|
|
|
|
use crate::{app::build_router, config::AppConfig, logging::init_tracing, state::AppState};
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), std::io::Error> {
|
|
// 统一先从配置对象读取监听地址,避免后续把环境变量读取散落到入口和路由层。
|
|
let config = AppConfig::from_env();
|
|
init_tracing(&config)?;
|
|
|
|
let bind_address = config.bind_socket_addr();
|
|
let listener = TcpListener::bind(bind_address).await?;
|
|
|
|
let state = AppState::new(config);
|
|
let router = build_router(state);
|
|
|
|
info!(%bind_address, "api-server 已完成 tracing 初始化并开始监听");
|
|
|
|
axum::serve(listener, router).await
|
|
}
|