41 lines
1.1 KiB
Lua
41 lines
1.1 KiB
Lua
|
|
---
|
||
|
|
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
||
|
|
--- Created by frankly.
|
||
|
|
--- DateTime: 2025/9/28 10:27
|
||
|
|
---
|
||
|
|
local radix = require("resty.radixtree")
|
||
|
|
local rx = radix.new({
|
||
|
|
{
|
||
|
|
paths = { "/login/*action" },
|
||
|
|
metadata = { "metadata /login/action" },
|
||
|
|
methods = { "GET", "POST", "PUT" },
|
||
|
|
remote_addrs = { "127.0.0.1", "192.168.0.0/16", "::1", "fe80::/32" }
|
||
|
|
},
|
||
|
|
{
|
||
|
|
paths = { "/user/:name" },
|
||
|
|
metadata = { "metadata /user/name" },
|
||
|
|
methods = { "GET" },
|
||
|
|
},
|
||
|
|
{
|
||
|
|
paths = { "/admin/:name", "/superuser/:name" },
|
||
|
|
metadata = { "metadata /admin/name" },
|
||
|
|
methods = { "GET", "POST", "PUT" },
|
||
|
|
filter_fun = function(vars, opts)
|
||
|
|
return vars["arg_access"] == "admin"
|
||
|
|
end
|
||
|
|
}
|
||
|
|
})
|
||
|
|
|
||
|
|
local opts = {
|
||
|
|
method = "POST",
|
||
|
|
remote_addr = "127.0.0.1",
|
||
|
|
matched = {}
|
||
|
|
}
|
||
|
|
|
||
|
|
-- matches the first route
|
||
|
|
ngx.say(rx:match("/login/update", opts)) -- metadata /login/action
|
||
|
|
ngx.say("action: ", opts.matched.action) -- action: update
|
||
|
|
|
||
|
|
ngx.say(rx:match("/login/register", opts)) -- metadata /login/action
|
||
|
|
ngx.say("action: ", opts.matched.action) -- action: register
|