feat: init meijiaka-zj project from ai-meijiaka template
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
# 配置架构规则
|
||||
|
||||
description: 配置管理架构规范
|
||||
|
||||
## 规则
|
||||
|
||||
### 配置读取
|
||||
- 所有配置必须通过 `from app.config import get_settings` 读取
|
||||
- 禁止直接使用 `os.getenv()` 或 `os.environ.get()`
|
||||
- 禁止在服务层、API 层直接使用环境变量
|
||||
|
||||
### 添加新配置
|
||||
1. 在 `app/config.py` 的 `Settings` 类中定义字段
|
||||
2. 使用 `Field(default=..., description="...")` 提供默认值和说明
|
||||
3. 敏感信息使用 `str | None = None` 类型
|
||||
4. 更新 `.env.example` 文档
|
||||
|
||||
### 在服务中使用配置
|
||||
```python
|
||||
from app.config import get_settings
|
||||
|
||||
def some_function():
|
||||
settings = get_settings()
|
||||
api_key = settings.SOME_API_KEY
|
||||
```
|
||||
|
||||
### 禁止的写法
|
||||
```python
|
||||
import os
|
||||
|
||||
# ❌ 禁止
|
||||
api_key = os.getenv("SOME_API_KEY")
|
||||
api_key = os.environ.get("SOME_API_KEY")
|
||||
```
|
||||
|
||||
### 推荐的写法
|
||||
```python
|
||||
from app.config import get_settings
|
||||
|
||||
# ✅ 正确
|
||||
settings = get_settings()
|
||||
api_key = settings.SOME_API_KEY
|
||||
```
|
||||
Reference in New Issue
Block a user