confi.get

This commit is contained in:
superobk
2024-05-16 16:30:33 +08:00
parent c7a5920be8
commit 9d9047d590
2 changed files with 4 additions and 16 deletions

View File

@ -8,13 +8,8 @@ from src.configuration import EnvConf, LogConf, singleton
class Main():
env_conf: EnvConf
@inject
def __init__(self, log_config: LogConf, env_conf: EnvConf, log_handler: LogHandler) -> None:
def __init__(self, log_config: LogConf, env_conf: EnvConf) -> None:
self.env_conf=env_conf
logging.basicConfig(
handlers=[log_handler],
level=log_config.level,
datefmt=log_config.time_format,
format='%(asctime)s %(message)s')
def run(self):
logger = logging.getLogger(__name__)

View File

@ -34,17 +34,10 @@ class Configuration():
return self.get(path.split("."), cfg)
length = len(path)
if length == 0 or not isinstance(cfg, dict):
return None
if length == 1:
return self.get(path.split("."), cfg, default=default)
lenght = len(path)
if lenght == 0 or not isinstance(cfg, dict):
if default is None:
return None
return default
if lenght == 1:
if length == 1:
return cfg.get(path[0])
return self.get(path[1:], cfg.get(path[0]), default=default)
return self.get(path[1:], cfg.get(path[0]))
class TesouConf():
url: str