Skip to content

Commit

Permalink
feature: remove lua dir. (apache#1351)
Browse files Browse the repository at this point in the history
  • Loading branch information
moonming authored and SaberMaster committed Jun 30, 2020
1 parent d5f7c54 commit 5d833ae
Show file tree
Hide file tree
Showing 92 changed files with 73 additions and 82 deletions.
18 changes: 9 additions & 9 deletions Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ Once we've discussed your changes and you've got your code ready, make sure that
$ make lint
luacheck -q lua
Total: 0 warnings / 0 errors in 74 files
./utils/lj-releng lua/*.lua \
lua/apisix/*.lua \
lua/apisix/admin/*.lua \
lua/apisix/core/*.lua \
lua/apisix/http/*.lua \
lua/apisix/http/router/*.lua \
lua/apisix/plugins/*.lua \
lua/apisix/plugins/grpc-transcode/*.lua \
lua/apisix/plugins/limit-count/*.lua > \
./utils/lj-releng \
apisix/*.lua \
apisix/admin/*.lua \
apisix/core/*.lua \
apisix/http/*.lua \
apisix/http/router/*.lua \
apisix/plugins/*.lua \
apisix/plugins/grpc-transcode/*.lua \
apisix/plugins/limit-count/*.lua > \
/tmp/check.log 2>&1 || (cat /tmp/check.log && exit 1)
```
* test case style
Expand Down
55 changes: 26 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -117,47 +117,44 @@ install:
$(INSTALL) conf/config.yaml /usr/local/apisix/conf/config.yaml
$(INSTALL) conf/cert/apisix.* /usr/local/apisix/conf/cert/

$(INSTALL) -d $(INST_LUADIR)/apisix/lua
$(INSTALL) lua/*.lua $(INST_LUADIR)/apisix/lua/
$(INSTALL) -d $(INST_LUADIR)/apisix
$(INSTALL) apisix/*.lua $(INST_LUADIR)/apisix/

$(INSTALL) -d $(INST_LUADIR)/apisix/lua/apisix
$(INSTALL) lua/apisix/*.lua $(INST_LUADIR)/apisix/lua/apisix/
$(INSTALL) -d $(INST_LUADIR)/apisix/admin
$(INSTALL) apisix/admin/*.lua $(INST_LUADIR)/apisix/admin/

$(INSTALL) -d $(INST_LUADIR)/apisix/lua/apisix/admin
$(INSTALL) lua/apisix/admin/*.lua $(INST_LUADIR)/apisix/lua/apisix/admin/
$(INSTALL) -d $(INST_LUADIR)/apisix/core
$(INSTALL) apisix/core/*.lua $(INST_LUADIR)/apisix/core/

$(INSTALL) -d $(INST_LUADIR)/apisix/lua/apisix/core
$(INSTALL) lua/apisix/core/*.lua $(INST_LUADIR)/apisix/lua/apisix/core/
$(INSTALL) -d $(INST_LUADIR)/apisix/http
$(INSTALL) apisix/http/*.lua $(INST_LUADIR)/apisix/http/

$(INSTALL) -d $(INST_LUADIR)/apisix/lua/apisix/http
$(INSTALL) lua/apisix/http/*.lua $(INST_LUADIR)/apisix/lua/apisix/http/
$(INSTALL) -d $(INST_LUADIR)/apisix/http/router
$(INSTALL) apisix/http/router/*.lua $(INST_LUADIR)/apisix/http/router/

$(INSTALL) -d $(INST_LUADIR)/apisix/lua/apisix/http/router
$(INSTALL) lua/apisix/http/router/*.lua $(INST_LUADIR)/apisix/lua/apisix/http/router/
$(INSTALL) -d $(INST_LUADIR)/apisix/plugins
$(INSTALL) apisix/plugins/*.lua $(INST_LUADIR)/apisix/plugins/

$(INSTALL) -d $(INST_LUADIR)/apisix/lua/apisix/plugins
$(INSTALL) lua/apisix/plugins/*.lua $(INST_LUADIR)/apisix/lua/apisix/plugins/
$(INSTALL) -d $(INST_LUADIR)/apisix/plugins/grpc-transcode
$(INSTALL) apisix/plugins/grpc-transcode/*.lua $(INST_LUADIR)/apisix/plugins/grpc-transcode/

$(INSTALL) -d $(INST_LUADIR)/apisix/lua/apisix/plugins/grpc-transcode
$(INSTALL) lua/apisix/plugins/grpc-transcode/*.lua $(INST_LUADIR)/apisix/lua/apisix/plugins/grpc-transcode/
$(INSTALL) -d $(INST_LUADIR)/apisix/plugins/limit-count
$(INSTALL) apisix/plugins/limit-count/*.lua $(INST_LUADIR)/apisix/plugins/limit-count/

$(INSTALL) -d $(INST_LUADIR)/apisix/lua/apisix/plugins/limit-count
$(INSTALL) lua/apisix/plugins/limit-count/*.lua $(INST_LUADIR)/apisix/lua/apisix/plugins/limit-count/
$(INSTALL) -d $(INST_LUADIR)/apisix/plugins/prometheus
$(INSTALL) apisix/plugins/prometheus/*.lua $(INST_LUADIR)/apisix/plugins/prometheus/

$(INSTALL) -d $(INST_LUADIR)/apisix/lua/apisix/plugins/prometheus
$(INSTALL) lua/apisix/plugins/prometheus/*.lua $(INST_LUADIR)/apisix/lua/apisix/plugins/prometheus/
$(INSTALL) -d $(INST_LUADIR)/apisix/plugins/zipkin
$(INSTALL) apisix/plugins/zipkin/*.lua $(INST_LUADIR)/apisix/plugins/zipkin/

$(INSTALL) -d $(INST_LUADIR)/apisix/lua/apisix/plugins/zipkin
$(INSTALL) lua/apisix/plugins/zipkin/*.lua $(INST_LUADIR)/apisix/lua/apisix/plugins/zipkin/
$(INSTALL) -d $(INST_LUADIR)/apisix/stream/plugins
$(INSTALL) apisix/stream/plugins/*.lua $(INST_LUADIR)/apisix/stream/plugins/

$(INSTALL) -d $(INST_LUADIR)/apisix/lua/apisix/stream/plugins
$(INSTALL) lua/apisix/stream/plugins/*.lua $(INST_LUADIR)/apisix/lua/apisix/stream/plugins/
$(INSTALL) -d $(INST_LUADIR)/apisix/stream/router
$(INSTALL) apisix/stream/router/*.lua $(INST_LUADIR)/apisix/stream/router/

$(INSTALL) -d $(INST_LUADIR)/apisix/lua/apisix/stream/router
$(INSTALL) lua/apisix/stream/router/*.lua $(INST_LUADIR)/apisix/lua/apisix/stream/router/

$(INSTALL) -d $(INST_LUADIR)/apisix/lua/apisix/utils
$(INSTALL) lua/apisix/utils/*.lua $(INST_LUADIR)/apisix/lua/apisix/utils/
$(INSTALL) -d $(INST_LUADIR)/apisix/utils
$(INSTALL) apisix/utils/*.lua $(INST_LUADIR)/apisix/utils/

$(INSTALL) README.md $(INST_CONFDIR)/README.md
$(INSTALL) bin/apisix $(INST_BINDIR)/apisix
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 6 additions & 12 deletions bin/apisix
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ local pkg_path_org = package.path
local apisix_home = "/usr/local/apisix"
local pkg_cpath = apisix_home .. "/deps/lib64/lua/5.1/?.so;"
.. apisix_home .. "/deps/lib/lua/5.1/?.so;;"
local pkg_path = apisix_home .. "/deps/share/lua/5.1/apisix/lua/?.lua;"
.. "/usr/local/share/lua/5.1/apisix/lua/?.lua;"
.. apisix_home .. "/deps/share/lua/5.1/?.lua;;"
local pkg_path = apisix_home .. "/deps/share/lua/5.1/?.lua;;"

-- only for developer, use current folder as working space
local is_root_path = false
Expand All @@ -58,7 +56,7 @@ if script_path:sub(1, 2) == './' then

pkg_cpath = apisix_home .. "/deps/lib64/lua/5.1/?.so;"
.. apisix_home .. "/deps/lib/lua/5.1/?.so;"
pkg_path = apisix_home .. "/lua/?.lua;"
pkg_path = apisix_home .. "/?/init.lua;"
.. apisix_home .. "/deps/share/lua/5.1/?.lua;;"
end
-- print("apisix_home: ", apisix_home)
Expand Down Expand Up @@ -113,10 +111,8 @@ env APISIX_PROFILE;
{% if stream_proxy then %}
stream {
lua_package_path "$prefix/deps/share/lua/5.1/?.lua;/usr/share/lua/5.1/apisix/lua/?.lua;]=]
.. [=[/usr/local/share/lua/5.1/apisix/lua/?.lua;]=]
.. [=[$prefix/deps/share/lua/5.1/apisix/lua/?.lua;]=]
.. [=[{*apisix_lua_home*}/lua/?.lua;;{*lua_path*};";
lua_package_path "$prefix/deps/share/lua/5.1/?.lua;]=]
.. [=[{*apisix_lua_home*}/?.lua;{*apisix_lua_home*}/?/init.lua;;{*lua_path*};";
lua_package_cpath "$prefix/deps/lib64/lua/5.1/?.so;]=]
.. [=[$prefix/deps/lib/lua/5.1/?.so;;]=]
.. [=[{*lua_cpath*};";
Expand Down Expand Up @@ -168,10 +164,8 @@ stream {
{% end %}
http {
lua_package_path "$prefix/deps/share/lua/5.1/?.lua;/usr/share/lua/5.1/apisix/lua/?.lua;]=]
.. [=[/usr/local/share/lua/5.1/apisix/lua/?.lua;]=]
.. [=[$prefix/deps/share/lua/5.1/apisix/lua/?.lua;]=]
.. [=[{*apisix_lua_home*}/lua/?.lua;;{*lua_path*};";
lua_package_path "$prefix/deps/share/lua/5.1/?.lua;]=]
.. [=[{*apisix_lua_home*}/?.lua;{*apisix_lua_home*}/?/init.lua;;{*lua_path*};";
lua_package_cpath "$prefix/deps/lib64/lua/5.1/?.so;]=]
.. [=[$prefix/deps/lib/lua/5.1/?.so;;]=]
.. [=[{*lua_cpath*};";
Expand Down
2 changes: 1 addition & 1 deletion doc/architecture-design-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ curl http://127.0.0.1:9080/apisix/admin/routes/102 -H 'X-API-KEY: edd1c9f034335f
优先级更高。

一个插件在一次请求中只会执行一次,即使被同时绑定到多个不同对象中(比如 Route 或 Service)。
插件运行先后顺序是根据插件自身的优先级来决定的,例如:[example-plugin](../lua/apisix/plugins/example-plugin.lua#L37)
插件运行先后顺序是根据插件自身的优先级来决定的,例如:[example-plugin](../apisix/plugins/example-plugin.lua#L37)

插件配置作为 Route 或 Service 的一部分提交的,放到 `plugins` 下。它内部是使用插件
名字作为哈希的 key 来保存不同插件的配置项。
Expand Down
2 changes: 1 addition & 1 deletion doc/architecture-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ The configuration of the plugin can be directly bound to the specified Route, or

A plugin will only be executed once in a single request, even if it is bound to multiple different objects (such as Route or Service).

The order in which plugins are run is determined by the priority of the plugin itself, for example: [example-plugin](../lua/apisix/plugins/example-plugin.lua#L37).
The order in which plugins are run is determined by the priority of the plugin itself, for example: [example-plugin](../apisix/plugins/example-plugin.lua#L37).

The plugin configuration is submitted as part of Route or Service and placed under `plugins`. It internally uses the plugin name as the hash's key to hold configuration items for different plugins.

Expand Down
4 changes: 2 additions & 2 deletions doc/plugin-develop-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@

插件本身提供了 init 方法。方便插件加载后做初始化动作。

注:如果部分插件的功能实现,需要在 Nginx 初始化启动,则可能需要在 __lua/apisix.lua__ 文件的初始化方法 http_init 中添加逻辑,并且
注:如果部分插件的功能实现,需要在 Nginx 初始化启动,则可能需要在 __apisix.lua__ 文件的初始化方法 http_init 中添加逻辑,并且
可能需要在 __bin/apisix__ 文件中,对 Nginx 配置文件生成的部分,添加一些你需要的处理。但是这样容易对全局产生影响,根据现有的
插件机制,我们不建议这样做,除非你已经对代码完全掌握。

## 插件命名与配置

给插件取一个很棒的名字,确定插件的加载优先级,然后在 __conf/config.yaml__ 文件中添加上你的插件名。例如 key-auth 这个插件,
需要在代码里指定插件名称(名称是插件的唯一标识,不可重名),在 __lua/apisix/plugins/key-auth.lua__ 文件中可以看到:
需要在代码里指定插件名称(名称是插件的唯一标识,不可重名),在 __apisix/plugins/key-auth.lua__ 文件中可以看到:

```lua
local plugin_name = "key-auth"
Expand Down
4 changes: 2 additions & 2 deletions doc/plugin-develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ The plugin itself provides the init method. It is convenient for plugins to perf
the plugin is loaded.

Note : if the dependency of some plugin needs to be initialized when Nginx start, you may need to add logic to the initialization
method "http_init" in the file __lua/apisix.lua__, And you may need to add some processing on generated part of Nginx
method "http_init" in the file __apisix.lua__, And you may need to add some processing on generated part of Nginx
configuration file in __bin/apisix__ file. but it is easy to have an impact on the overall situation according to the
existing plugin mechanism, we do not recommend this unless you have a complete grasp of the code.

## name and config

determine the name and priority of the plugin, and add to conf/config.yaml. For example, for the key-auth plugin,
you need to specify the plugin name in the code (the name is the unique identifier of the plugin and cannot be
duplicate), you can see the code in file "__lua/apisix/plugins/key-auth.lua__" :
duplicate), you can see the code in file "__apisix/plugins/key-auth.lua__" :

```lua
local plugin_name = "key-auth"
Expand Down
4 changes: 2 additions & 2 deletions t/APISIX.pm
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ _EOC_

my $stream_enable = $block->stream_enable;
my $stream_config = $block->stream_config // <<_EOC_;
lua_package_path "$apisix_home/deps/share/lua/5.1/?.lua;$apisix_home/lua/?.lua;$apisix_home/t/?.lua;./?.lua;;";
lua_package_path "$apisix_home/deps/share/lua/5.1/?.lua;$apisix_home/apisix/?.lua;$apisix_home/t/?.lua;./?.lua;./?/init.lua;;";
lua_package_cpath "$apisix_home/deps/lib/lua/5.1/?.so;$apisix_home/deps/lib64/lua/5.1/?.so;./?.so;;";
lua_socket_log_errors off;
Expand Down Expand Up @@ -186,7 +186,7 @@ _EOC_

my $http_config = $block->http_config // '';
$http_config .= <<_EOC_;
lua_package_path "$apisix_home/deps/share/lua/5.1/?.lua;$apisix_home/lua/?.lua;$apisix_home/t/?.lua;./?.lua;;";
lua_package_path "$apisix_home/deps/share/lua/5.1/?.lua;$apisix_home/apisix/?.lua;$apisix_home/t/?.lua;./?.lua;./?/init.lua;;";
lua_package_cpath "$apisix_home/deps/lib/lua/5.1/?.so;$apisix_home/deps/lib64/lua/5.1/?.so;./?.so;;";
lua_shared_dict plugin-limit-req 10m;
Expand Down
28 changes: 14 additions & 14 deletions t/apisix.luacov
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
return {
modules = {
["lua.*"] = "lua",
["lua/apisix/*"] = "apisix",
["lua/apisix/admin/*"] = "admin",
["lua/apisix/core/*"] = "core",
["lua/apisix/http/*"] = "http",
["lua/apisix/http/router/*"] = "http/router",
["lua/apisix/plugins/*"] = "plugins",
["lua/apisix/plugins/grpc-transcode/*"] = "plugins/grpc-transcode",
["lua/apisix/plugins/limit-count/*"] = "plugins/limit-count",
["lua/apisix/plugins/prometheus/*"] = "plugins/prometheus",
["lua/apisix/plugins/zipkin/*"] = "plugins/zipkin",
["lua/apisix/utils/*"] = "utils",
["apisix/*"] = "apisix",
["apisix/admin/*"] = "admin",
["apisix/core/*"] = "core",
["apisix/http/*"] = "http",
["apisix/http/router/*"] = "http/router",
["apisix/plugins/*"] = "plugins",
["apisix/plugins/grpc-transcode/*"] = "plugins/grpc-transcode",
["apisix/plugins/limit-count/*"] = "plugins/limit-count",
["apisix/plugins/prometheus/*"] = "plugins/prometheus",
["apisix/plugins/zipkin/*"] = "plugins/zipkin",
["apisix/utils/*"] = "utils",

-- can not enable both at http and stream, will fix it later.
-- ["lua/apisix/stream/*"] = "stream",
-- ["lua/apisix/stream/plugins/*"] = "stream/plugins",
-- ["lua/apisix/stream/router/*"] = "stream/router",
-- ["apisix/stream/*"] = "stream",
-- ["apisix/stream/plugins/*"] = "stream/plugins",
-- ["apisix/stream/router/*"] = "stream/router",
},
}
20 changes: 10 additions & 10 deletions utils/check-lua-code-style.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@

set -ex

luacheck -q lua
luacheck -q apisix

./utils/lj-releng lua/*.lua \
lua/apisix/*.lua \
lua/apisix/admin/*.lua \
lua/apisix/core/*.lua \
lua/apisix/http/*.lua \
lua/apisix/http/router/*.lua \
lua/apisix/plugins/*.lua \
lua/apisix/plugins/grpc-transcode/*.lua \
lua/apisix/plugins/limit-count/*.lua > \
./utils/lj-releng \
apisix/*.lua \
apisix/admin/*.lua \
apisix/core/*.lua \
apisix/http/*.lua \
apisix/http/router/*.lua \
apisix/plugins/*.lua \
apisix/plugins/grpc-transcode/*.lua \
apisix/plugins/limit-count/*.lua > \
/tmp/check.log 2>&1 || (cat /tmp/check.log && exit 1)

grep -E "ERROR.*.lua:" /tmp/check.log > /tmp/error.log | true
Expand Down

0 comments on commit 5d833ae

Please sign in to comment.