From e75a66b910becd7b4574bae7837459ce95f1665c Mon Sep 17 00:00:00 2001 From: dabue <53054094+dabue@users.noreply.github.com> Date: Tue, 28 Apr 2020 02:53:29 -0500 Subject: [PATCH] doc: fix the doc style for serverless*.md (#1511) --- doc/plugins/serverless-cn.md | 26 ++++++++++++++++++-------- doc/plugins/serverless.md | 14 +++++++++----- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/doc/plugins/serverless-cn.md b/doc/plugins/serverless-cn.md index be8e7c84a4fb..fab9ad9e5a0b 100644 --- a/doc/plugins/serverless-cn.md +++ b/doc/plugins/serverless-cn.md @@ -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 @@ -46,14 +51,16 @@ end ``` 但不是函数类型的代码就是非法的: -``` + +```lua local count = 1 ngx.say(count) ``` -### 示例 +## 示例 + +### 启动插件 -#### 启动插件 下面是一个示例,在指定的 route 上开启了 serverless 插件: ```shell @@ -75,8 +82,10 @@ 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 ``` @@ -84,7 +93,8 @@ curl -i http://127.0.0.1:9080/index.html 然后你在 error.log 日志中就会发现 `serverless pre function` 这个 error 级别的日志, 表示指定的函数已经生效。 -#### 移除插件 +### 移除插件 + 当你想去掉插件的时候,很简单,在插件的配置中把对应的 json 配置删除即可,无须重启服务,即刻生效: ```shell diff --git a/doc/plugins/serverless.md b/doc/plugins/serverless.md index c3a722f652d7..bb6a30fb35f0 100644 --- a/doc/plugins/serverless.md +++ b/doc/plugins/serverless.md @@ -20,6 +20,7 @@ [Chinese](serverless-cn.md) # Summary + - [**Name**](#name) - [**Attributes**](#attributes) - [**How To Enable**](#how-to-enable) @@ -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:
-``` + +```lua return function() ngx.log(ngx.ERR, 'one') end ``` Closure is also legal: -``` + +```lua local count = 1 return function() count = count + 1 @@ -59,7 +61,8 @@ end ``` But code that is not a function type is illegal: - ``` + +```lua local count = 1 ngx.say(count) ``` @@ -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 ```