Files
ai_site/platform/README.md
2026-07-31 10:31:17 +08:00

81 lines
1.8 KiB
Markdown
Raw Permalink 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.
# Platformgo-zero骨架
Publish校验蓝图 → 分配 schema → 生成/执行 DDL → 注册元数据)+ 动态 CRUD + JWT。
## 目录
```text
platform/
platform.go
docker-compose.yml # 本地 Postgres
etc/platform.yaml
internal/
authx/ # JWT 签发/校验 + Dev 头兜底
blueprint/
schema/ # Postgres DDL数值 PK 用 IDENTITY
meta/
crud/ # MemoryEngine + PostgresEngine
logic/applogic/
handler/
```
## 运行(内存 + JWT
```bash
cd platform
go test ./...
go run . -f etc/platform.yaml
# 另开终端
go run ./scripts/smoke.go
```
冒烟会:签发 JWT → publish → create → list → 非法 token 应 401。
## 运行Postgres 行级 Engine
```bash
docker compose up -d
```
`etc/platform.yaml`
```yaml
DataSource: "postgres://platform:platform@127.0.0.1:5432/platform?sslmode=disable"
DevAuth: false
```
再启动服务。此时:
- publish **真实建 schema/表**
- CRUD 走 `PostgresEngine`(参数化 SQL + `tenant_id` 强制条件)
## JWT
```http
POST /api/v1/auth/token
{"tenant_id":1,"user_id":1,"secret":"dev-only-change-me"}
{"access_token":"...","token_type":"Bearer","expires_at":...}
```
业务请求:
```http
Authorization: Bearer <access_token>
```
| 配置 | 行为 |
|------|------|
| `DevAuth: false` | 必须带合法 JWT |
| `DevAuth: true` | 无 JWT 时可用 `X-Tenant-Id` / `X-User-Id`(仅本地) |
| 带了错误 Bearer | 一律 401即使 DevAuth=true |
生产请更换 `Auth.AccessSecret` / `IssueSecret`,并关掉 `DevAuth`
## 元数据落库
启用 DataSource 后自动迁移并使用 `platform_meta.tenant_apps`
- 存 blueprint / ddl / endpoints / status
- 进程重启后仍可按 slug 解析动态 CRUD
- 无库时回退内存 `MemoryStore`