Added singleton config and changed module structure

This commit is contained in:
2023-11-23 22:13:10 +03:00
parent 6389c4f29e
commit 8c2d706401
12 changed files with 41 additions and 29 deletions

19
neuroapi/config.py Normal file
View File

@@ -0,0 +1,19 @@
import os
from typing import Self
from dotenv import load_dotenv
class _Singleton:
_instances = {}
def __new__(cls) -> Self:
if cls not in cls._instances:
cls._instances[cls] = super(_Singleton, cls).__new__(cls)
return cls._instances[cls]
class Config(_Singleton):
api_url: str
def __init__(self):
load_dotenv(os.path.join(os.path.dirname(__file__), '..', '.env'))
self.api_url = os.environ.get('API_URL')