23 lines
883 B
Markdown
23 lines
883 B
Markdown
# Transport adapters
|
||
|
||
GoOmni 的业务处理链依赖 `httpx.Router`,不直接依赖具体网络框架。当前的 `transport/gin` 只负责把 Gin 的路由、路径参数和响应写入转换成标准 HTTP 接口;`transport/nethttp` 提供了一个只使用标准库的参考实现。
|
||
|
||
使用标准库适配器:
|
||
|
||
```go
|
||
import (
|
||
omni "git.yuntuo.hk/k2safe/go-omni"
|
||
netrouter "git.yuntuo.hk/k2safe/go-omni/transport/nethttp"
|
||
)
|
||
|
||
application := omni.NewWithRouter(netrouter.New())
|
||
```
|
||
|
||
后续自研网络层时,实现以下能力即可接入现有 `app`、中间件和业务 Handler:
|
||
|
||
- `httpx.Router`:注册路由、分组并实现 `http.Handler`。
|
||
- `httpx.RouterGroup`:注册分组内路由。
|
||
- 适配器为请求 context 注入 `httpx.WithRouteParams` 和 `httpx.WithRoutePattern`。
|
||
|
||
业务层不应该导入具体 transport 包;它们只是网络层实现。
|