refactor: don't force plugin to use /vn prefix (#3081)

This commit is contained in:
罗泽轩 2020-12-21 10:38:10 +08:00 committed by GitHub
parent 31b49ad0e1
commit 7c158b739a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 18 deletions

View File

@ -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, ...)

View File

@ -18,7 +18,6 @@ local _M = {}
function _M.schema()
-- stub for test yet, fill it in the next PR
return 200, {}
end

View File

@ -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