Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the doc style for serverless*.md #1511

Merged
merged 1 commit into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions doc/plugins/serverless-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,29 @@
[English](serverless.md)

# serverless

serverless 的插件有两个,分别是 `serverless-pre-function` 和 `serverless-post-function`,
前者会在指定阶段的最开始运行,后者是在指定阶段的最后运行。

这两个插件接收的参数都是一样的。

### Parameters
## Parameters

* `phase`: 指定的运行阶段,没有指定的话默认是 `access`。允许的阶段有:`rewrite`、`access`
`header_filer`、`body_filter`、`log` 和 `balancer` 阶段。
* `functions`: 指定运行的函数列表,是数组类型,里面可以包含一个函数,也可以是多个函数,按照先后顺序执行。

需要注意的是,这里只接受函数,而不接受其他类型的 Lua 代码。比如匿名函数是合法的:
```

```lua
return function()
ngx.log(ngx.ERR, 'one')
end
```

闭包也是合法的:
```

```lua
local count = 1
return function()
count = count + 1
Expand All @@ -46,14 +51,16 @@ end
```

但不是函数类型的代码就是非法的:
```

```lua
local count = 1
ngx.say(count)
```

### 示例
## 示例

### 启动插件

#### 启动插件
下面是一个示例,在指定的 route 上开启了 serverless 插件:

```shell
Expand All @@ -75,16 +82,19 @@ curl -i http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f03433
}'
```

#### 测试插件
### 测试插件

使用 curl 访问:

```shell
curl -i http://127.0.0.1:9080/index.html
```

然后你在 error.log 日志中就会发现 `serverless pre function` 这个 error 级别的日志,
表示指定的函数已经生效。

#### 移除插件
### 移除插件

当你想去掉插件的时候,很简单,在插件的配置中把对应的 json 配置删除即可,无须重启服务,即刻生效:

```shell
Expand Down
14 changes: 9 additions & 5 deletions doc/plugins/serverless.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
[Chinese](serverless-cn.md)

# Summary

- [**Name**](#name)
- [**Attributes**](#attributes)
- [**How To Enable**](#how-to-enable)
Expand All @@ -41,16 +42,17 @@ Both plug-ins receive the same parameters.
| phase |optional|The default phase is `access`, if not specified. The valid phases are: `rewrite`, `access`,`Header_filer`, `body_filter`, `log` and `balancer`.|
| functions |required|A list of functions that are specified to run is an array type, which can contain either one function or multiple functions, executed sequentially.|


Note that only function is accepted here, not other types of Lua code. For example, anonymous functions are legal:<br>
```

```lua
return function()
ngx.log(ngx.ERR, 'one')
end
```

Closure is also legal:
```

```lua
local count = 1
return function()
count = count + 1
Expand All @@ -59,7 +61,8 @@ end
```

But code that is not a function type is illegal:
```

```lua
local count = 1
ngx.say(count)
```
Expand Down Expand Up @@ -90,7 +93,8 @@ curl -i http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f03433
## Test Plugin

Use curl to access:
```shell

```shell
curl -i http://127.0.0.1:9080/index.html
```

Expand Down