Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: removed useless split uri for admin APIs. #146

Merged
merged 3 commits into from
Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions lua/apisix/admin/consumers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ local _M = {
}


local function check_conf(uri_segs, conf)
local function check_conf(consumer_name, conf)
-- core.log.error(core.json.encode(conf))
if not conf then
return nil, {error_msg = "missing configurations"}
end

local consumer_name = conf.username or uri_segs[5]
local consumer_name = conf.username or consumer_name
if not consumer_name then
return nil, {error_msg = "missing consumer name"}
end
Expand All @@ -27,8 +27,8 @@ local function check_conf(uri_segs, conf)
end


function _M.put(uri_segs, conf)
local consumer_name, err = check_conf(uri_segs, conf)
function _M.put(consumer_name, conf)
local consumer_name, err = check_conf(consumer_name, conf)
if not consumer_name then
return 400, err
end
Expand All @@ -45,8 +45,7 @@ function _M.put(uri_segs, conf)
end


function _M.get(uri_segs)
local consumer_name = uri_segs[5]
function _M.get(consumer_name)
local key = "/consumers"
if consumer_name then
key = key .. "/" .. consumer_name
Expand All @@ -62,13 +61,12 @@ function _M.get(uri_segs)
end


function _M.post(uri_segs, conf)
function _M.post(consumer_name, conf)
return 400, {error_msg = "not support `POST` method for consumer"}
end


function _M.delete(uri_segs)
local consumer_name = uri_segs[5]
function _M.delete(consumer_name)
if not consumer_name then
return 400, {error_msg = "missing consumer name"}
end
Expand Down
10 changes: 1 addition & 9 deletions lua/apisix/admin/init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
local get_var = require("resty.ngxvar").fetch
local core = require("apisix.core")
local route = require("resty.r3")
local get_method = ngx.req.get_method
Expand Down Expand Up @@ -30,13 +29,6 @@ local function run(params)
core.response.exit(404)
end

local segments, err = core.utils.split_uri(get_var("uri"))
if not segments then
core.log.error("failed to split uri: ", err)
core.response.exit(500)
end
core.log.info("split uri: ", core.json.delay_encode(segments))

ngx.req.read_body()
local req_body = ngx.req.get_body_data()

Expand All @@ -51,7 +43,7 @@ local function run(params)
req_body = data
end

local code, data = resource[method](segments, req_body)
local code, data = resource[method](params.id, req_body)
if code then
core.response.exit(code, data)
end
Expand Down
17 changes: 7 additions & 10 deletions lua/apisix/admin/routes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ local _M = {
}


local function check_conf(uri_segs, conf, need_id)
local function check_conf(id, conf, need_id)
if not conf then
return nil, {error_msg = "missing configurations"}
end

local id = uri_segs[5]
id = id or conf.id
if need_id and not id then
return nil, {error_msg = "missing route id"}
Expand Down Expand Up @@ -79,8 +78,8 @@ local function check_conf(uri_segs, conf, need_id)
end


function _M.put(uri_segs, conf)
local id, err = check_conf(uri_segs, conf, true)
function _M.put(id, conf)
local id, err = check_conf(id, conf, true)
if not id then
return 400, err
end
Expand All @@ -96,8 +95,7 @@ function _M.put(uri_segs, conf)
end


function _M.get(uri_segs)
local id = uri_segs[5]
function _M.get(id)
local key = "/routes"
if id then
key = key .. "/" .. id
Expand All @@ -113,8 +111,8 @@ function _M.get(uri_segs)
end


function _M.post(uri_segs, conf)
local id, err = check_conf(uri_segs, conf, false)
function _M.post(id, conf)
local id, err = check_conf(id, conf, false)
if not id then
return 400, err
end
Expand All @@ -131,8 +129,7 @@ function _M.post(uri_segs, conf)
end


function _M.delete(uri_segs)
local id = uri_segs[5]
function _M.delete(id)
if not id then
return 400, {error_msg = "missing route id"}
end
Expand Down
17 changes: 7 additions & 10 deletions lua/apisix/admin/services.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ local _M = {
}


local function check_conf(uri_segs, conf, need_id)
local function check_conf(id, conf, need_id)
if not conf then
return nil, {error_msg = "missing configurations"}
end

local id = uri_segs[5]
id = id or conf.id
if need_id and not id then
return nil, {error_msg = "missing service id"}
Expand Down Expand Up @@ -70,8 +69,8 @@ local function check_conf(uri_segs, conf, need_id)
end


function _M.put(uri_segs, conf)
local id, err = check_conf(uri_segs, conf, true)
function _M.put(id, conf)
local id, err = check_conf(id, conf, true)
if not id then
return 400, err
end
Expand All @@ -88,8 +87,7 @@ function _M.put(uri_segs, conf)
end


function _M.get(uri_segs)
local id = uri_segs[5]
function _M.get(id)
local key = "/services"
if id then
key = key .. "/" .. id
Expand All @@ -105,8 +103,8 @@ function _M.get(uri_segs)
end


function _M.post(uri_segs, conf)
local id, err = check_conf(uri_segs, conf, false)
function _M.post(id, conf)
local id, err = check_conf(id, conf, false)
if not id then
return 400, err
end
Expand All @@ -122,9 +120,8 @@ function _M.post(uri_segs, conf)
end


function _M.delete(uri_segs)
function _M.delete(id)
-- todo: need to check if any route is still using this service now.
local id = uri_segs[5]
if not id then
return 400, {error_msg = "missing service id"}
end
Expand Down
17 changes: 7 additions & 10 deletions lua/apisix/admin/upstreams.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ local _M = {
}


local function check_conf(uri_segs, conf, need_id)
local function check_conf(id, conf, need_id)
if not conf then
return nil, {error_msg = "missing configurations"}
end

local id = uri_segs[5]
id = id or conf.id
if need_id and not id then
return nil, {error_msg = "missing upstream id"}
Expand Down Expand Up @@ -50,8 +49,8 @@ local function check_conf(uri_segs, conf, need_id)
end


function _M.put(uri_segs, conf)
local id, err = check_conf(uri_segs, conf, true)
function _M.put(id, conf)
local id, err = check_conf(id, conf, true)
if not id then
return 400, err
end
Expand All @@ -68,8 +67,7 @@ function _M.put(uri_segs, conf)
end


function _M.get(uri_segs)
local id = uri_segs[5]
function _M.get(id)
local key = "/upstreams"
if id then
key = key .. "/" .. id
Expand All @@ -85,8 +83,8 @@ function _M.get(uri_segs)
end


function _M.post(uri_segs, conf)
local id, err = check_conf(uri_segs, conf, false)
function _M.post(id, conf)
local id, err = check_conf(id, conf, false)
if not id then
return 400, err
end
Expand All @@ -102,8 +100,7 @@ function _M.post(uri_segs, conf)
end


function _M.delete(uri_segs)
local id = uri_segs[5]
function _M.delete(id)
if not id then
return 400, {error_msg = "missing upstream id"}
end
Expand Down