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.

34 lines
694B

  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. raise Exception('配置文件不存在,请根据config-template.json模板创建config.json文件')
  11. config_str = read_file(config_path)
  12. # 将json字符串反序列化为dict类型
  13. config = json.loads(config_str)
  14. logger.info("[INIT] load config: {}".format(config))
  15. def get_root():
  16. return os.path.dirname(os.path.abspath( __file__ ))
  17. def read_file(path):
  18. with open(path, mode='r', encoding='utf-8') as f:
  19. return f.read()
  20. def conf():
  21. return config