Добавлены миддлвари на примере ThrottlingMiddleware

This commit is contained in:
Forden
2020-04-06 00:58:24 +03:00
parent 90791c3091
commit c3da772339
9 changed files with 96 additions and 2 deletions

16
utils/misc/throttling.py Normal file
View File

@@ -0,0 +1,16 @@
def rate_limit(limit: int, key=None):
"""
Decorator for configuring rate limit and key in different functions.
:param limit:
:param key:
:return:
"""
def decorator(func):
setattr(func, 'throttling_rate_limit', limit)
if key:
setattr(func, 'throttling_key', key)
return func
return decorator