from fastapi import FastAPI from app.api import Server, ShortCircuit from app.api.ShortCircuit import app_start def register_blueprints(app): ''' registration route (module) ''' # app.include_router(Server.router, tags=["API接口"]) app.include_router(ShortCircuit.router, tags=["电池短路API接口"]) async def lifespan(app): # 应用启动时执行 await app_start() # 在应用关闭时执行的代码 yield # 等待应用关闭 def create_app(): app = FastAPI(lifespan=lifespan) #注册路由 register_blueprints(app) return app