feature:基本框架
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
"""应用入口:四库异步生命周期 + 中间件 + 全局异常 + 路由装配。"""
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
from api.router import api_router
|
||||
from config import database
|
||||
from utils.exceptions import register_exception_handlers
|
||||
from utils.logger import setup_logging
|
||||
from utils.request_id import RequestIdMiddleware
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
setup_logging() # 幂等:分级日志 + trace_id + 脱敏
|
||||
# 四库会话懒创建:启动不连接任何库,首次访问才建,可手动预热:
|
||||
# asyncio.run(database.init_db())
|
||||
yield
|
||||
await database.dispose() # 清理已创建的单例(未创建则空操作)
|
||||
|
||||
|
||||
app = FastAPI(title="智能公募基金系统", version="0.1.0", lifespan=lifespan)
|
||||
|
||||
app.add_middleware(RequestIdMiddleware)
|
||||
register_exception_handlers(app)
|
||||
app.include_router(api_router)
|
||||
|
||||
|
||||
@app.get("/")
|
||||
async def root():
|
||||
return {"message": "智能公募基金系统 API", "docs": "/docs"}
|
||||
Reference in New Issue
Block a user