""" 应用配置管理 使用 pydantic-settings 从环境变量读取配置 """ from pydantic_settings import BaseSettings from functools import lru_cache class Settings(BaseSettings): """应用配置""" DATABASE_URL: str = "mysql+pymysql://root:password@localhost:3306/yuzong" SECRET_KEY: str = "your-secret-key-change-this" ALGORITHM: str = "HS256" ACCESS_TOKEN_EXPIRE_MINUTES: int = 1440 UPLOAD_DIR: str = "uploads" class Config: env_file = ".env" env_file_encoding = "utf-8" @lru_cache() def get_settings() -> Settings: """获取配置单例""" return Settings() settings = get_settings()