baodan/api/insurance/config.py

15 lines
438 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""公共配置:统一从环境变量或 Flask config 读取配置项。"""
import os
from flask import current_app
def get_config(key: str, default: str = "") -> str:
"""从环境变量获取配置(优先级:环境变量 > Flask config"""
value = os.environ.get(key, "")
if value:
return value
try:
return current_app.config.get(key, default)
except RuntimeError:
return default