You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/02/21 01:24:05 UTC

[GitHub] [apisix] tokers commented on a change in pull request #6370: Update plugin-develop.md

tokers commented on a change in pull request #6370:
URL: https://github.com/apache/apisix/pull/6370#discussion_r810721032



##########
File path: docs/zh/latest/plugin-develop.md
##########
@@ -37,6 +38,50 @@ title: 插件开发
 - [编写测试用例](#编写测试用例)
   - [附上 test-nginx 执行流程](#附上-test-nginx-执行流程)
 
+此文档是关于lua语言的插件开发,其他语言请看:[external plugin](./external-plugin.md)。
+
+## 插件放置路径
+
+wAPISIX提供了两种方式来添加新的功能。

Review comment:
       ```suggestion
   APISIX提供了两种方式来添加新的功能。
   ```

##########
File path: docs/zh/latest/plugin-develop.md
##########
@@ -37,6 +38,50 @@ title: 插件开发
 - [编写测试用例](#编写测试用例)
   - [附上 test-nginx 执行流程](#附上-test-nginx-执行流程)
 
+此文档是关于lua语言的插件开发,其他语言请看:[external plugin](./external-plugin.md)。
+
+## 插件放置路径
+
+wAPISIX提供了两种方式来添加新的功能。
+
+1. 修改APISIX的源代码并重新发布 (不推荐)。
+1. 配置  `extra_lua_path` 和 `extra_lua_cpath` 在 `conf/config.yaml`以加载你自己的代码文件。 你应该给自己的代码文件起一个不包含在原来库中的名字,而不是使用相同名称的代码文件,但是如果有需要,你可以使用这种方式覆盖内置的代码文件。
+
+比如,你可以创建一个目录目录结构,像下面这样:
+
+```
+├── example
+│   └── apisix
+│       ├── plugins
+│       │   └── 3rd-party.lua
+│       └── stream
+│           └── plugins
+│               └── 3rd-party.lua
+```
+
+接着,在`conf/config.yaml`文件中添加如下的配置:
+
+```yaml
+apisix:
+    ...
+    extra_lua_path: "/path/to/example/?.lua"
+```
+
+现在使用 `require "apisix.plugins.3rd-party"` 会加载你自己的插件, 比如 `require "apisix.plugins.jwt-auth"`会加载 `jwt-auth` 插件.
+
+可能你会想覆盖一个文件中的函数,你可以在`conf/config.yaml`文件中配置`lua_module_hook` 来使你的hook生效。
+
+你的配置可以像下面这样:
+
+```yaml
+apisix:
+    ...
+    extra_lua_path: "/path/to/example/?.lua"
+    lua_module_hook: "my_hook"
+```
+
+ 当APISIX启动的时候,`example/my_hook.lua` 就会被加载,这时你可以使用这个钩子在APISIX中来全局替换掉一个方法。
+这个例子: [my_hook.lua](https://github.com/apache/apisix/blob/master/example/my_hook.lua) 可以在项目的`example`路径下被找到。

Review comment:
       ```suggestion
   这个例子: [my_hook.lua](https://github.com/apache/apisix/blob/master/example/my_hook.lua) 可以在项目的`example`路径下被找到。
   
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org