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.

33 line
695B

  1. import json
  2. import os
  3. from common.log import logger
  4. config = {}
  5. def load_config():
  6. global config
  7. config_path = "config.json"
  8. try:
  9. if not os.path.exists(config_path):
  10. logger.error('配置文件路径不存在')
  11. return
  12. config_str = read_file(config_path)
  13. # 将json字符串反序列化为dict类型
  14. config = json.loads(config_str)
  15. logger.info("[INIT] load config: {}".format(config))
  16. except Exception as e:
  17. logger.error(e)
  18. def get_root():
  19. return os.path.dirname(os.path.abspath( __file__ ))
  20. def read_file(path):
  21. with open(path, 'r') as f:
  22. return f.read()
  23. def conf():
  24. return config