Files
go-omni/examples/modules/README.md

34 lines
1.4 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.
# 基础模块组合示例
在仓库根目录执行:
```sh
go run ./examples/modules
```
默认监听 `127.0.0.1:8080`,使用仅限开发的 `Bearer dev-token`。
配置 `GO_OMNI_TRANSPORT=native` 可直接切换自研网络层,TLS 配置与主框架一致。
```sh
curl -H 'Authorization: Bearer dev-token' http://127.0.0.1:8080/api/catalog
curl -H 'Authorization: Bearer dev-token' -H 'Content-Type: application/json' \
-H 'Idempotency-Key: report-1' -d '{"name":"report"}' http://127.0.0.1:8080/api/jobs
curl -H 'Authorization: Bearer dev-token' http://127.0.0.1:8080/api/jobs
```
catalog 缓存 30 秒;可通过启动环境变量 `GO_OMNI_DEMO_UPSTREAM` 指定可信 JSON 上游,
演示 HTTP 连接池、请求 ID 传递与合并回源。URL 来自服务配置,不接受请求参数传入。
jobs 展示固定 worker、队列、结构化日志与状态查询;相同 Idempotency-Key 和请求内容重放
第一次 202 响应,内容不同返回 409。每分钟的统计任务演示间隔调度。退出先排空任务,再关闭
HTTP 客户端和缓存。这个示例的任务、缓存和幂等记录均保存在进程内。
组合测试通过真实 TLS 连接覆盖 nethttp、native 和实验 HTTP/2,检查缓存回源次数、
幂等重放、认证不可被重放绕过、任务只提交一次与关闭流程:
```sh
go test -race ./examples/modules
```
完整 API、默认上限和适用范围见 [业务基础模块](../../MODULES.md)。