Skip to content

Commit

Permalink
web parameter doc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
gqcn committed Feb 28, 2025
1 parent b15c401 commit 29c2766
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/docs/WEB服务开发/常见问题.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description: '解答有关在使用GoFrame框架时服务端频繁出现context

## 服务端频繁出现 `context cancel` 错误

**客户端主动取消请求**(例如主动取消,或者请求超过客户端设置的时间)后,特别是浏览器访问时直接取消请求,服务端可能会遇到 `context canceled` 的错误。这个属于正常现象, `Golang` 标准库的 `http server` 设计亦如此。当客户端不再需要这个请求的结果时会取消请求,这时服务端继续往下执行也没有了意义。如果介意这个错误,可以使用一个自定义的中间件增加 `NeverDoneCtx` 的处理逻辑,这个时候服务端会忽略客户端的取消请求并继续往下执行。
**客户端主动取消请求**(例如主动取消,或者请求超过客户端设置的时间)后,特别是浏览器访问时直接取消请求,服务端可能会遇到 `context canceled` 的错误。这个属于正常现象, `Golang` 标准库的 `http server` 设计亦如此。当客户端不再需要这个请求的结果时会取消请求,这时服务端继续往下执行也没有了意义。如果介意这个错误,可以使用一个自定义的中间件增加 `NeverDoneCtx` 的处理逻辑,或者直接使用框架提供的`ghttp.MiddlewareNeverDoneCtx`中间件。这个时候服务端会忽略客户端的取消请求并继续往下执行。

```go
// MiddlewareNeverDoneCtx sets the context never done for current process.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
slug: '/docs/web/request-complicated-parameters'
title: '请求输入-复杂参数'
slug: '/docs/web/request-parameters'
title: '请求输入-参数处理'
sidebar_position: 0
hide_title: true
keywords: [GoFrame,GoFrame框架,复杂参数,请求输入,Query参数,Form参数,JSON数据,HTTP Server,数组参数,Map参数]
Expand Down Expand Up @@ -47,7 +47,9 @@ func main() {

执行后,我们访问 [http://127.0.0.1:8199/?name=john&name=smith](http://127.0.0.1:8199/?name=john&name=smith) 后,将会得到返回值 `smith`

:::warning
注意:框架的 `HTTP Server` 在这块的处理逻辑参考 `PHP`,会和 `Go` 标准库的处理逻辑有所差异。在 `Go` 标准库 `net/http` 处理中,提交的同名参数将会被转换为字符串数组。
:::

## 数组参数

Expand All @@ -72,9 +74,11 @@ func main() {
```

执行后,我们访问 [http://127.0.0.1:8199/?array\[\]=john&array\[\]=smith](http://127.0.0.1:8199/?array[]=john&array[]=smith) 后,将会得到返回值 `["john","smith"]`

:::warning
注意:如果传递的参数带有中括号以及 **索引号**,那么该参数按照前面介绍的复杂参数转换规则将会被转换为 `map`。例如, `array[0]=john&array[1]=smith`,将会被转换为 `map{"0":"john","1":"smith"}`
:::

## `Map` 参数

`Map` 参数提交格式形如: `k[a]=m&k[b]=n`,并且支持多级 `Map`,例如: `k[a][a]=m&k[a][b]=n`
Expand Down

0 comments on commit 29c2766

Please sign in to comment.