Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/toritori0318/lua-resty-r3
libr3 Lua-Openresty implementation
https://github.com/toritori0318/lua-resty-r3
Last synced: 9 days ago
JSON representation
libr3 Lua-Openresty implementation
- Host: GitHub
- URL: https://github.com/toritori0318/lua-resty-r3
- Owner: toritori0318
- License: mit
- Created: 2015-12-20T17:32:16.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2015-12-23T16:31:07.000Z (almost 9 years ago)
- Last Synced: 2024-04-15T02:06:54.891Z (7 months ago)
- Language: Lua
- Size: 6.84 KB
- Stars: 40
- Watchers: 5
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-resty - lua-resty-r3 - performance path dispatching library. It compiles your route paths into a prefix tree (trie). By using the constructed prefix trie in the start-up time, you may dispatch your routes with efficiency (Libraries)
README
lua-resty-r3
================[libr3](https://github.com/c9s/r3) Lua-Openresty implementation.
**This repository is an experimental.**
## Install
### libr3
[See.](https://github.com/c9s/r3#install)
### lua-resty-r3
```
luarocks install https://raw.githubusercontent.com/toritori0318/lua-resty-r3/master/lua-resty-r3-dev-1.rockspec
```## SYNOPSYS
### Pattern1
```lua
location / {
content_by_lua '
-- foo handler
function foo(tokens, params)
ngx.say("fooooooooooooooooooooooo")
ngx.say("tokens:" .. table.concat(tokens, ","))
for key, value in pairs(params) do
ngx.say("param:" .. key .. "=" .. value)
end
end-- r3router
local r3router = require "resty.r3";
local r = r3router.new()
-- routing
r:get("/", function(tokens, params)
ngx.say("hello r3!")
end)
r:get("/foo", foo)
r:get("/foo/{id}/{name}", foo)
r:post("/foo/{id}/{name}", foo)
-- don\'t forget!
r:compile()-- dispatcher
local ok = r:dispatch_ngx()
---- or manual
---- local ok = r:dispatch("GET", "/foo/123/999", ngx.req.get_uri_args(), ngx.req.get_post_args())
if ok then
ngx.status = 200
else
ngx.status = 404
ngx.print("Not found")
end
';
}
```### Pattern2
```lua
location / {
content_by_lua '
-- foo handler
function foo(tokens, params)
ngx.say("fooooooooooooooooooooooo")
ngx.say("tokens:" .. table.concat(tokens, ","))
for key, value in pairs(params) do
ngx.say("param:" .. key .. "=" .. value)
end
end-- r3router
local r3router = require "resty.r3";
local r = r3router.new({
{"GET", "/", function(t, p) ngx.say("hello r3!") end },
{"GET", "/foo", foo},
{{"GET","POST"}, "/foo/{id}/{name}", foo},
})-- dispatcher
local ok = r:dispatch_ngx()
---- or manual
---- local ok = r:dispatch("GET", "/foo/123/999", ngx.req.get_uri_args(), ngx.req.get_post_args())
if ok then
ngx.status = 200
else
ngx.status = 404
ngx.print("Not found")
end
';
}
```## Docker Setup
```
cd /path/to/lua-resty-r3
docker run -p 89:80 -v "$(pwd)":/code -it toritori0318/lua-resty-r3 /opt/openresty/nginx/sbin/nginx
```