-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.py
40 lines (26 loc) · 861 Bytes
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
from pathlib import Path
from functools import lru_cache
import pytomlpp
from pydantic import BaseModel
from conf.settings import LogSetting, ServiceSetting, SocketIOSetting
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
class Setting(BaseModel):
log: LogSetting
service: ServiceSetting
socket_io: SocketIOSetting
@lru_cache()
def get_settings() -> Setting:
CODE_ENV = os.environ.get('CODE_ENV', 'prd')
if CODE_ENV == 'test':
p = Path(BASE_DIR).joinpath('conf/test.local.toml')
else:
p = Path(BASE_DIR).joinpath('conf/product.local.toml')
if not p.is_file():
raise Exception('config no exists')
settings = Setting.parse_obj(pytomlpp.load(p))
return settings
Config = get_settings()
LogConfig = Config.log
ServiceConfig = Config.service
SocketIOConfig = Config.socket_io