from functools import lru_cache from pydantic_settings import BaseSettings, SettingsConfigDict class Settings(BaseSettings): app_name: str = "dating-mini-program-api" app_env: str = "development" app_debug: bool = True api_v1_prefix: str = "/api/v1" mysql_host: str = "127.0.0.1" mysql_port: int = 3306 mysql_user: str = "root" mysql_password: str = "" mysql_database: str = "dating_app" redis_host: str = "127.0.0.1" redis_port: int = 6379 redis_db: int = 0 redis_password: str = "" jwt_secret_key: str = "replace_with_a_secure_secret" jwt_algorithm: str = "HS256" jwt_access_token_expire_minutes: int = 10080 wx_appid: str = "" wx_secret: str = "" wx_miniprogram_page_activity_detail: str = "pages/activity-detail/activity-detail" wx_template_audit_result: str = "" wx_template_match_success: str = "" cos_region: str = "" cos_secret_id: str = "" cos_secret_key: str = "" cos_bucket: str = "" cos_base_url: str = "" model_config = SettingsConfigDict( env_file=".env", env_file_encoding="utf-8", case_sensitive=False, extra="ignore", ) @property def database_url(self) -> str: return ( f"mysql+asyncmy://{self.mysql_user}:{self.mysql_password}" f"@{self.mysql_host}:{self.mysql_port}/{self.mysql_database}?charset=utf8mb4" ) @property def redis_url(self) -> str: auth = f":{self.redis_password}@" if self.redis_password else "" return f"redis://{auth}{self.redis_host}:{self.redis_port}/{self.redis_db}" @lru_cache def get_settings() -> Settings: return Settings() settings = get_settings()