修改文件目录,修改配置文件
This commit is contained in:
parent
d36a0edbec
commit
30d16de03b
|
@ -22,11 +22,18 @@ http {
|
||||||
location /api {
|
location /api {
|
||||||
content_by_lua_file '/home/frankly/work/AuthPlatform/src/api/api.lua';
|
content_by_lua_file '/home/frankly/work/AuthPlatform/src/api/api.lua';
|
||||||
}
|
}
|
||||||
|
|
||||||
location /testTree {
|
location /testTree {
|
||||||
content_by_lua_file '/home/frankly/work/AuthPlatform/src/testRadixtree.lua';
|
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testRadixtree.lua';
|
||||||
}
|
}
|
||||||
location /test {
|
location /testSQL {
|
||||||
content_by_lua_file '/home/frankly/work/AuthPlatform/src/testPostgres.lua';
|
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testPostgres.lua';
|
||||||
|
}
|
||||||
|
location /testRedis {
|
||||||
|
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testRedis.lua';
|
||||||
|
}
|
||||||
|
location /testObj {
|
||||||
|
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testObjClass.lua';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
5
src/test/testObjClass.lua
Normal file
5
src/test/testObjClass.lua
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
||||||
|
--- Created by frankly.
|
||||||
|
--- DateTime: 2025/9/29 10:14
|
||||||
|
---
|
40
src/test/testRadixtree.lua
Normal file
40
src/test/testRadixtree.lua
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
---
|
||||||
|
--- 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
|
45
src/test/testRedis.lua
Normal file
45
src/test/testRedis.lua
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
---
|
||||||
|
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
||||||
|
--- Created by frankly.
|
||||||
|
--- DateTime: 2025/9/29 10:10
|
||||||
|
---
|
||||||
|
|
||||||
|
local redis = require("resty.redis")
|
||||||
|
local red = redis:new()
|
||||||
|
|
||||||
|
-- 设置超时时间
|
||||||
|
red:set_timeout(1000) -- 1秒
|
||||||
|
|
||||||
|
-- 连接到 Redis
|
||||||
|
local ok, err = red:connect("127.0.0.1", 6379)
|
||||||
|
if not ok then
|
||||||
|
ngx.say("failed to connect: ", err)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 设置 key-value
|
||||||
|
local ok, err = red:set("some_key", "hello world")
|
||||||
|
if not ok then
|
||||||
|
ngx.say("failed to set key: ", err)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
ngx.say("set key successfully")
|
||||||
|
|
||||||
|
-- 获取 key 的值
|
||||||
|
local res, err = red:get("some_key")
|
||||||
|
if err then
|
||||||
|
ngx.say("failed to get key: ", err)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if res then
|
||||||
|
ngx.say("got: ", res)
|
||||||
|
else
|
||||||
|
ngx.say("key not found.")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 关闭连接
|
||||||
|
local ok, err = red:set_keepalive(10000, 50) -- 空闲10秒,最大空闲连接数50
|
||||||
|
if not ok then
|
||||||
|
ngx.say("failed to set keepalive: ", err)
|
||||||
|
return
|
||||||
|
end
|
|
@ -1,13 +0,0 @@
|
||||||
---
|
|
||||||
--- 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({
|
|
||||||
path = "/api/*",
|
|
||||||
host = "*.example.com",
|
|
||||||
method = "GET",
|
|
||||||
remote_addr = "127.0.0.1"
|
|
||||||
})
|
|
||||||
ngx.say(rx.match("/api/v1/data", {path = "/api/v1/data"}) == true)
|
|
Loading…
Reference in New Issue
Block a user