Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
gqcn committed Nov 6, 2024
1 parent be44632 commit 1378afe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 15 additions & 1 deletion docs/quick/快速开始/中间件初试用.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,21 @@ func main() {

## 执行结果

运行后,我们访问 http://127.0.0.1:8000/?name=john&age=18 可以看到,页面输出结果符合预期。
运行后,终端输出:

```text
2024-11-06 22:30:06.927 [INFO] pid[35434]: http server started listening on [:8000]
2024-11-06 22:30:06.927 [INFO] {905637567a67051830833b2189796dda} openapi specification is disabled
ADDRESS | METHOD | ROUTE | HANDLER | MIDDLEWARE
----------|--------|-------|-------------------|--------------------
:8000 | GET | / | main.(*Hello).Say | main.ErrorHandler
----------|--------|-------|-------------------|--------------------
```
这里的`MIDDLEWARE`部分多了一个`main.ErrorHandler`方法,表示该路由绑定的中间件名称。


我们访问 http://127.0.0.1:8000/?name=john&age=18 可以看到,页面输出结果符合预期。

![img.png](img.png)

Expand Down
4 changes: 2 additions & 2 deletions docs/quick/快速开始/生成接口文档.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func main() {
### 终端输出

执行后,终端输出:
```html
```text
2024-10-28 21:56:42.747 [INFO] pid[87280]: http server started listening on [:8000]
2024-10-28 21:56:42.747 [INFO] {d84db2976ea202187ba40f5d0657e4d7} swagger ui is serving at address: http://127.0.0.1:8000/swagger/
2024-10-28 21:56:42.747 [INFO] {d84db2976ea202187ba40f5d0657e4d7} openapi specification is serving at address: http://127.0.0.1:8000/api.json
Expand All @@ -142,7 +142,7 @@ func main() {
我们可以看到,终端输出的提示信息发生了一些变化:
- 终端输出了`swagger`的地址`http://127.0.0.1:8000/swagger/`点击该地址可以直接打开`Swagger UI`界面。
- 终端输出了`openapi`的接口文档地址`http://127.0.0.1:8000/api.json`,该地址文件可以使用很多接口文档UI查看工具打开。
- 路由信息也多了两行地址,对应的是`swagger``openapi`的地址。
- 路由信息也多了两行地址,对应的是`swagger``openapi`的地址。其中`swagger`的路由地址使用了`Server``HOOK`钩子特性,`HOOK`是一种比中间件更加自由的请求拦截方式,可以同时拦截动态接口和静态资源请求。有固定的几种埋点`HOOK`,这里使用的埋点是`HOOK_BEFORE_SERVE`,具体的细节请查看开发手册中`Web Server`的相关章节,这里不展开介绍。

### `Swagger UI`

Expand Down

0 comments on commit 1378afe

Please sign in to comment.