初始化
This commit is contained in:
40
app/core/config.py
Normal file
40
app/core/config.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from pydantic_settings import BaseSettings
|
||||
from functools import lru_cache
|
||||
|
||||
class Settings(BaseSettings):
|
||||
# 应用配置
|
||||
APP_HOST: str = "0.0.0.0"
|
||||
APP_PORT: int = 8000
|
||||
APP_DEBUG: bool = True
|
||||
|
||||
# Railway数据库配置
|
||||
RAILWAY_DB_HOST: str = "localhost"
|
||||
RAILWAY_DB_PORT: int = 3306
|
||||
RAILWAY_DB_USER: str = "root"
|
||||
RAILWAY_DB_PASSWORD: str = ""
|
||||
RAILWAY_DB_NAME: str = "railway"
|
||||
|
||||
# Tunnel数据库配置
|
||||
TUNNEL_DB_HOST: str = "localhost"
|
||||
TUNNEL_DB_PORT: int = 3306
|
||||
TUNNEL_DB_USER: str = "root"
|
||||
TUNNEL_DB_PASSWORD: str = ""
|
||||
TUNNEL_DB_NAME: str = "Tunnel"
|
||||
|
||||
@property
|
||||
def RAILWAY_DATABASE_URL(self) -> str:
|
||||
return f"mysql+pymysql://{self.RAILWAY_DB_USER}:{self.RAILWAY_DB_PASSWORD}@{self.RAILWAY_DB_HOST}:{self.RAILWAY_DB_PORT}/{self.RAILWAY_DB_NAME}?charset=utf8mb4"
|
||||
|
||||
@property
|
||||
def TUNNEL_DATABASE_URL(self) -> str:
|
||||
return f"mysql+pymysql://{self.TUNNEL_DB_USER}:{self.TUNNEL_DB_PASSWORD}@{self.TUNNEL_DB_HOST}:{self.TUNNEL_DB_PORT}/{self.TUNNEL_DB_NAME}?charset=utf8mb4"
|
||||
|
||||
class Config:
|
||||
env_file = ".env"
|
||||
extra = "ignore"
|
||||
|
||||
@lru_cache()
|
||||
def get_settings():
|
||||
return Settings()
|
||||
|
||||
settings = get_settings()
|
||||
Reference in New Issue
Block a user