Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

config.py 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839
  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