Closed rexyan closed 5 years ago
根据环境去加载配置,实例化对象的时候直接传入环境变量名称,默认配置路径为summer.config,也可传入传入config路径(待优化,可用于打包后上层应用传入自己的配置文件) 例子:config['DEBUG'] 取用当前环境下的DEBUG的值,没有则返回None
class ConfigManager(object): config_map = { 'development': 'DevelopmentConfig', 'testing': 'TestingConfig' } def __init__(self, env_key, config_dir=None): config_dir = config_dir if config_dir else '.'.join(['summer', 'config']) self._content = dict() self.current_config_obj = None self.env_key = env_key # 默认加载development配置 def __getitem__(self, item): # 获取环境变量中配置的值 def read(self, relative_path): # 找到对应的配置文件,并导入 return self
根据环境去加载配置,实例化对象的时候直接传入环境变量名称,默认配置路径为summer.config,也可传入传入config路径(待优化,可用于打包后上层应用传入自己的配置文件) 例子:config['DEBUG'] 取用当前环境下的DEBUG的值,没有则返回None