From 7c158b739a4cd30e56bd286854e2d3e48b1b552a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BD=97=E6=B3=BD=E8=BD=A9?= Date: Mon, 21 Dec 2020 10:38:10 +0800 Subject: [PATCH] refactor: don't force plugin to use /vn prefix (#3081) --- apisix/control/router.lua | 13 ++++++------- apisix/control/v1.lua | 1 - apisix/plugins/example-plugin.lua | 17 +++++++---------- t/control/{v1.t => plugin-api.t} | 0 4 files changed, 13 insertions(+), 18 deletions(-) rename t/control/{v1.t => plugin-api.t} (100%) diff --git a/apisix/control/router.lua b/apisix/control/router.lua index 221d2234..86ea7694 100644 --- a/apisix/control/router.lua +++ b/apisix/control/router.lua @@ -27,7 +27,6 @@ local get_method = ngx.req.get_method local _M = {} -local current_version = 1 local fetch_control_api_router @@ -57,24 +56,24 @@ do local function empty_func() end function fetch_control_api_router() - core.table.clear(v1_routes) - - register_api_routes(v1_routes, builtin_v1_routes) + core.table.clear(routes) for _, plugin in ipairs(plugin_mod.plugins) do local api_fun = plugin.control_api if api_fun then - local api_routes = api_fun(current_version) - register_api_routes(v1_routes, api_routes) + local api_route = api_fun() + register_api_routes(routes, api_route) end end + core.table.clear(v1_routes) + register_api_routes(v1_routes, builtin_v1_routes) + local v1_router, err = router.new(v1_routes) if not v1_router then return nil, err end - core.table.clear(routes) core.table.insert(routes, { paths = {"/v1/*"}, filter_fun = function(vars, opts, ...) diff --git a/apisix/control/v1.lua b/apisix/control/v1.lua index 7ad795e4..3d959a55 100644 --- a/apisix/control/v1.lua +++ b/apisix/control/v1.lua @@ -18,7 +18,6 @@ local _M = {} function _M.schema() - -- stub for test yet, fill it in the next PR return 200, {} end diff --git a/apisix/plugins/example-plugin.lua b/apisix/plugins/example-plugin.lua index c94a7a4e..089b0184 100644 --- a/apisix/plugins/example-plugin.lua +++ b/apisix/plugins/example-plugin.lua @@ -120,17 +120,14 @@ local function hello() end -function _M.control_api(ver) - if ver == 1 then - return { - -- /v1/plugin/example-plugin/hello - { - methods = {"GET"}, - uris = {"/plugin/example-plugin/hello"}, - handler = hello, - } +function _M.control_api() + return { + { + methods = {"GET"}, + uris = {"/v1/plugin/example-plugin/hello"}, + handler = hello, } - end + } end diff --git a/t/control/v1.t b/t/control/plugin-api.t similarity index 100% rename from t/control/v1.t rename to t/control/plugin-api.t