Files
lijiaoqiao/gateway/README.md
Your Name 88d842648d chore(repo): align integrity entrypoints with current state
Rewrite module READMEs around the current verified run and test paths, tighten repo_integrity_check.sh with fact-source checks, update supply-api migration baseline, and remove the platform-token-runtime audit query placeholder response.
2026-04-14 12:29:13 +08:00

64 lines
1.9 KiB
Markdown
Raw 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.
# Gateway
> OpenAI 兼容入口网关,负责接入、鉴权、限流、上游路由与基础审计。
## 当前真实状态
- 服务入口是 `cmd/gateway/main.go`
- 当前对外暴露的主要接口是 `/v1/chat/completions``/v1/completions``/v1/models`,以及对应的 `/api/v1/*` 兼容路径。
- 鉴权运行时支持两种模式:
- `inmemory`
- `remote_introspection`
- provider 注册已经从配置装配;如果未显式配置 provider启动时会基于环境变量生成默认 OpenAI provider。
- 审计发射器支持 PostgreSQL 与内存实现;数据库未配置时会显式回退到内存实现。
## 与其他服务的边界
- `gateway` 不签发业务 token。
- `gateway``remote_introspection` 模式下依赖 `platform-token-runtime` 提供 token introspection。
- `gateway` 只承载入口控制,不承载 `supply-api``platform-token-runtime` 的业务逻辑。
## 本地运行
```bash
cd "/home/long/project/立交桥/gateway"
export OPENAI_API_KEY="..."
export OPENAI_BASE_URL="https://api.openai.com"
export OPENAI_MODELS="gpt-4,gpt-3.5-turbo"
export GATEWAY_ENV="dev"
export GATEWAY_TOKEN_RUNTIME_MODE="inmemory"
go run ./cmd/gateway
```
如果要切到远程 token 校验:
```bash
export GATEWAY_TOKEN_RUNTIME_MODE="remote_introspection"
export GATEWAY_TOKEN_RUNTIME_URL="http://127.0.0.1:18081"
```
默认监听 `0.0.0.0:8080`
## 验证命令
模块级验证:
```bash
cd "/home/long/project/立交桥/gateway"
GOCACHE=/tmp/lijiaoqiao-go-cache-gateway go test ./...
```
仓库级统一验证:
```bash
cd "/home/long/project/立交桥"
bash scripts/ci/repo_integrity_check.sh
```
## 关键目录
- `internal/config/`:环境变量配置与 provider 配置加载。
- `internal/handler/`OpenAI 兼容 HTTP handler。
- `internal/middleware/`鉴权、CORS、远程 introspection。
- `internal/router/`provider 路由、打分与 fallback。