You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.0KB

  1. # encoding:utf-8
  2. import json
  3. import os
  4. from common.log import logger
  5. config = {}
  6. def load_config():
  7. global config
  8. config_path = "./config.json"
  9. if not os.path.exists(config_path):
  10. logger.info('配置文件不存在,将使用config-template.json模板')
  11. config_path = "./config-template.json"
  12. config_str = read_file(config_path)
  13. # 将json字符串反序列化为dict类型
  14. config = json.loads(config_str)
  15. # override config with environment variables.
  16. # Some online deployment platforms (e.g. Railway) deploy project from github directly. So you shouldn't put your secrets like api key in a config file, instead use environment variables to override the default config.
  17. for name, value in os.environ.items():
  18. config[name] = value
  19. logger.info("[INIT] load config: {}".format(config))
  20. def get_root():
  21. return os.path.dirname(os.path.abspath( __file__ ))
  22. def read_file(path):
  23. with open(path, mode='r', encoding='utf-8') as f:
  24. return f.read()
  25. def conf():
  26. return config