2019-07-26 17:16:31 +08:00
|
|
|
local json_decode = require("cjson").decode
|
|
|
|
|
2019-06-17 23:17:41 +08:00
|
|
|
local _M = {}
|
|
|
|
|
|
|
|
|
|
|
|
function _M.hello()
|
|
|
|
ngx.say("hello world")
|
|
|
|
end
|
|
|
|
|
2019-07-25 16:06:07 +08:00
|
|
|
function _M.hello1()
|
|
|
|
ngx.say("hello1 world")
|
|
|
|
end
|
|
|
|
|
2019-06-17 23:17:41 +08:00
|
|
|
|
|
|
|
function _M.server_port()
|
|
|
|
ngx.print(ngx.var.server_port)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2019-06-24 17:02:53 +08:00
|
|
|
function _M.limit_conn()
|
|
|
|
ngx.sleep(0.3)
|
|
|
|
ngx.say("hello world")
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2019-07-17 23:52:15 +08:00
|
|
|
function _M.status()
|
|
|
|
ngx.say("ok")
|
|
|
|
end
|
|
|
|
|
2019-07-22 11:27:30 +08:00
|
|
|
function _M.sleep1()
|
|
|
|
ngx.sleep(1)
|
|
|
|
ngx.say("ok")
|
|
|
|
end
|
|
|
|
|
2019-07-17 23:52:15 +08:00
|
|
|
|
2019-07-26 17:16:31 +08:00
|
|
|
function _M.opentracing()
|
|
|
|
ngx.say("opentracing")
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function _M.mock_zipkin()
|
|
|
|
ngx.req.read_body()
|
|
|
|
local data = ngx.req.get_body_data()
|
|
|
|
local spans = json_decode(data)
|
|
|
|
if #spans < 5 then
|
|
|
|
ngx.exit(400)
|
|
|
|
end
|
|
|
|
|
|
|
|
for _, span in pairs(spans) do
|
|
|
|
if string.sub(span.name, 1, 6) ~= 'apisix' then
|
|
|
|
ngx.exit(400)
|
|
|
|
end
|
|
|
|
if not span.traceId then
|
|
|
|
ngx.exit(400)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2019-06-17 23:17:41 +08:00
|
|
|
function _M.go()
|
|
|
|
local action = string.sub(ngx.var.uri, 2)
|
2019-08-12 09:04:41 +08:00
|
|
|
local find = string.find(action, "/", 1, true)
|
|
|
|
if find then
|
|
|
|
action = string.sub(action, 1, find - 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
if not action or not _M[action] then
|
2019-06-17 23:17:41 +08:00
|
|
|
return ngx.exit(404)
|
|
|
|
end
|
|
|
|
|
|
|
|
return _M[action]()
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
return _M
|