-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
43 lines (33 loc) · 1023 Bytes
/
main.py
File metadata and controls
43 lines (33 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi_cache import FastAPICache
from fastapi_cache.backends.redis import RedisBackend
from fastapi_cache.decorator import cache
from redis import asyncio as aioredis
from api_v1 import register_routers
from app_includes import (
register_errors,
register_middlewares,
register_prometheus,
)
from config import settings
def start_app() -> FastAPI:
"""
Создание приложения со всеми настройками
"""
app = FastAPI(lifespan=lifespan)
register_routers(app=app)
register_errors(app=app)
register_middlewares(app=app)
register_prometheus(app=app)
return app
@asynccontextmanager
async def lifespan(app: FastAPI):
redis = aioredis.from_url(settings.redis.redis_url)
FastAPICache.init(RedisBackend(redis), prefix='fastapi-cache')
yield
app = start_app()
@app.get(path='/test')
@cache()
async def test_end_point():
return dict(hello='world')