This commit is contained in:
superobk
2024-05-16 16:09:25 +08:00
2 changed files with 10 additions and 4 deletions

View File

@ -7,19 +7,18 @@ from src.configuration import EnvConf, LogConf, singleton
@singleton @singleton
class Main(): class Main():
env_conf: EnvConf env_conf: EnvConf
@inject @inject
def __init__(self, log_config: LogConf, env_conf: EnvConf, log_handler: LogHandler) -> None: def __init__(self, log_config: LogConf, env_conf: EnvConf, log_handler: LogHandler) -> None:
self.env_conf=env_conf self.env_conf=env_conf
logging.basicConfig( logging.basicConfig(
handlers=[logging.StreamHandler()], handlers=[log_handler],
level=log_config.level, level=log_config.level,
datefmt=log_config.time_format, datefmt=log_config.time_format,
format='%(asctime)s %(message)s') format='%(asctime)s %(message)s')
def run(self): def run(self):
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
logger.info("jarvis-models start", extra={"version": "0.0.1"}) logger.info("jarvis-models start", "version", "0.0.1")
uvicorn.run("server:app", host="0.0.0.0", port=8000, log_level="info") uvicorn.run("server:app", host="0.0.0.0", port=8000, log_level="info")
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -36,6 +36,13 @@ class Configuration():
if length == 0 or not isinstance(cfg, dict): if length == 0 or not isinstance(cfg, dict):
return None return None
if length == 1: 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:
return cfg.get(path[0]) 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]), default=default)
@ -87,4 +94,4 @@ class EnvConf():
@inject @inject
def __init__(self, config: Configuration) -> None: def __init__(self, config: Configuration) -> None:
self.version = config.get("env.version") self.version = config.get("env.version")