diff --git a/.dockerignore b/.dockerignore index 5602aec..0ed8a8b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -25,4 +25,5 @@ desktop.ini #логи и временные файлы *.log *.tmp -*.temp \ No newline at end of file + +*.temp diff --git a/.env.example b/.env.example index 7fe423d..43f3b3c 100644 --- a/.env.example +++ b/.env.example @@ -5,4 +5,5 @@ REDIS_PORT=6379 # APP_HOST=0.0.0.0 # APP_PORT=8000 -# DEBUG=True \ No newline at end of file + +# DEBUG=True diff --git a/.gitignore b/.gitignore index 2eb619a..a4e4ba4 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ __pycache__/ dump.rdb *.rdb .env -Thumbs.db \ No newline at end of file + +Thumbs.db diff --git a/Dockerfile b/Dockerfile index 408ff9d..c672042 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,4 +12,5 @@ COPY . . EXPOSE 8000 #запуск приложения -CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] \ No newline at end of file + +CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] diff --git a/README.md b/README.md index 69f1108..16c0b94 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Rate Limiter API -REST API сервис для ограничения частоты запросов по алгоритму Fixed Window. Поддерживает глобальные лимиты и лимиты по IP-адресу клиента. +REST API сервис для ограничения частоты запросов по алгоритму Fixed Window. Поддерживает глобальные лимиты и лимиты по IP-адресу клиента. ### Запуск через Docker @@ -57,4 +57,5 @@ rate_limiter/ ├── .env.example ├── .dockerignore └── .gitignore -``` \ No newline at end of file + +``` diff --git a/docker-compose.yml b/docker-compose.yml index 5eeada7..aad00b0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3.8' +version: '3.8' services: redis: @@ -24,3 +24,4 @@ services: - .:/app volumes: redis-data: + diff --git a/main.py b/main.py index 318e2c4..7b0016f 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,4 @@ -from fastapi import FastAPI, HTTPException, Request +from fastapi import FastAPI, HTTPException, Request from pydantic import BaseModel from rate_limit import RateLimiter @@ -125,4 +125,5 @@ def reset_counters(): limiter.reset_counters() return {"status": "успех", "message": "Все счетчики сброшены"} except Exception as e: - raise HTTPException(status_code=500, detail=f"Ошибка сброса: {str(e)}") \ No newline at end of file + + raise HTTPException(status_code=500, detail=f"Ошибка сброса: {str(e)}") diff --git a/rate_limit.py b/rate_limit.py index 94552e0..daf1807 100644 --- a/rate_limit.py +++ b/rate_limit.py @@ -1,6 +1,6 @@ from storage import RedisStorage from typing import Dict, Tuple, Optional -import time +import time class RateLimiter: def __init__(self): @@ -92,4 +92,5 @@ def reset_counters(self): def _get_current_window(self, window_seconds: int) -> str: current_time = int(time.time()) window_number = current_time // window_seconds - return str(window_number) \ No newline at end of file + + return str(window_number) diff --git a/requirements.txt b/requirements.txt index b7baac2..97801e8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ fastapi==0.100.0 uvicorn==0.24.0 redis==5.0.1 pydantic==2.12.5 -python-dotenv==1.0.0 \ No newline at end of file + +python-dotenv==1.0.0 diff --git a/storage.py b/storage.py index 67ec4fb..bf0bd55 100644 --- a/storage.py +++ b/storage.py @@ -1,5 +1,5 @@ import redis -import json +import json import os from dotenv import load_dotenv @@ -30,4 +30,5 @@ def load_config(self, config_key: str, default_config: dict) -> dict: return default_config def is_connected(self) -> bool: - return self.redis.ping() \ No newline at end of file + + return self.redis.ping()