Migrate the backends handler logic to function

This commit is contained in:
Lisheng Zheng 2020-02-26 18:03:13 +08:00
parent d8f84fde6a
commit f2e5d6f8a5

View file

@ -155,34 +155,8 @@ local function handle_certs()
end end
end end
function _M.call()
if ngx.var.request_method ~= "POST" and ngx.var.request_method ~= "GET" then
ngx.status = ngx.HTTP_BAD_REQUEST
ngx.print("Only POST and GET requests are allowed!")
return
end
if ngx.var.request_uri == "/configuration/servers" then
handle_servers()
return
end
if ngx.var.request_uri == "/configuration/general" then
handle_general()
return
end
if ngx.var.uri == "/configuration/certs" then
handle_certs()
return
end
if ngx.var.request_uri ~= "/configuration/backends" then
ngx.status = ngx.HTTP_NOT_FOUND
ngx.print("Not found!")
return
end
local function handle_backends()
if ngx.var.request_method == "GET" then if ngx.var.request_method == "GET" then
ngx.status = ngx.HTTP_OK ngx.status = ngx.HTTP_OK
ngx.print(_M.get_backends_data()) ngx.print(_M.get_backends_data())
@ -206,6 +180,37 @@ function _M.call()
ngx.status = ngx.HTTP_CREATED ngx.status = ngx.HTTP_CREATED
end end
function _M.call()
if ngx.var.request_method ~= "POST" and ngx.var.request_method ~= "GET" then
ngx.status = ngx.HTTP_BAD_REQUEST
ngx.print("Only POST and GET requests are allowed!")
return
end
if ngx.var.request_uri == "/configuration/servers" then
handle_servers()
return
end
if ngx.var.request_uri == "/configuration/general" then
handle_general()
return
end
if ngx.var.uri == "/configuration/certs" then
handle_certs()
return
end
if ngx.var.request_uri == "/configuration/backends" then
handle_backends()
return
end
ngx.status = ngx.HTTP_NOT_FOUND
ngx.print("Not found!")
end
if _TEST then if _TEST then
_M.handle_servers = handle_servers _M.handle_servers = handle_servers
end end