-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: define regex pattern in variables
- Loading branch information
Showing
20 changed files
with
484 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
unused_args = false | ||
max_line_length = false | ||
redefined = false | ||
|
||
globals = { | ||
"ngx", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
local Router = require "radix-router" | ||
local utils = require "benchmark.utils" | ||
|
||
local route_n = os.getenv("RADIX_ROUTER_ROUTES") or 1000 * 100 | ||
local times = os.getenv("RADIX_ROUTER_TIMES") or 1000 * 1000 * 10 | ||
|
||
local router | ||
do | ||
local routes = {} | ||
for i = 1, route_n do | ||
routes[i] = { paths = { string.format("/%d/{name:[^/]+}", i) }, handler = i } | ||
end | ||
router = Router.new(routes) | ||
end | ||
|
||
local rss_mb = utils.get_rss() | ||
|
||
local path = "/1/a" | ||
local elapsed = utils.timing(function() | ||
for _ = 1, times do | ||
router:match(path) | ||
end | ||
end) | ||
|
||
utils.print_result({ | ||
title = "regex", | ||
routes = route_n, | ||
times = times, | ||
elapsed = elapsed, | ||
benchmark_path = path, | ||
benchmark_handler = router:match(path), | ||
rss = rss_mb, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env resty | ||
|
||
if ngx ~= nil then | ||
ngx.exit = function()end | ||
end | ||
|
||
require 'busted.runner'({ standalone = false }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
<html> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> | ||
<head> | ||
<title>Reference</title> | ||
<link rel="stylesheet" href="../ldoc.css" type="text/css" /> | ||
</head> | ||
<body> | ||
|
||
<div id="container"> | ||
|
||
<div id="product"> | ||
<div id="product_logo"></div> | ||
<div id="product_name"><big><b></b></big></div> | ||
<div id="product_description"></div> | ||
</div> <!-- id="product" --> | ||
|
||
|
||
<div id="main"> | ||
|
||
|
||
<!-- Menu --> | ||
|
||
<div id="navigation"> | ||
<br/> | ||
<h1>Radix-Router</h1> | ||
|
||
|
||
|
||
|
||
|
||
<h2>Examples</h2> | ||
<ul class="nowrap"> | ||
<li><a href="../examples/custom-matcher.lua.html">custom-matcher.lua</a></li> | ||
<li><a href="../examples/example.lua.html">example.lua</a></li> | ||
<li><strong>regular-expression.lua</strong></li> | ||
</ul> | ||
<h2>Modules</h2> | ||
<ul class="nowrap"> | ||
<li><a href="../index.html">radix-router</a></li> | ||
</ul> | ||
|
||
</div> | ||
|
||
<div id="content"> | ||
|
||
<h2>regular-expression.lua</h2> | ||
<pre> | ||
<span class="keyword">local</span> Router = <span class="global">require</span> <span class="string">"radix-router"</span> | ||
<span class="keyword">local</span> router, err = Router.<span class="function-name">new</span>({ | ||
{ | ||
paths = { <span class="string">"/users/{id:\\d+}/profile-{year:\\d{4}}.{format:(html|pdf)}"</span> }, | ||
handler = <span class="string">"1"</span> | ||
}, | ||
{ | ||
paths = { <span class="string">"/users/{uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}}"</span> }, | ||
handler = <span class="string">"2"</span> | ||
}, | ||
}) | ||
<span class="keyword">if</span> <span class="keyword">not</span> router <span class="keyword">then</span> | ||
<span class="global">error</span>(<span class="string">"failed to create router: "</span> .. err) | ||
<span class="keyword">end</span> | ||
|
||
<span class="global">assert</span>(<span class="string">"1"</span> == router:<span class="function-name">match</span>(<span class="string">"/users/100/profile-2024.pdf"</span>)) | ||
<span class="global">assert</span>(<span class="string">"2"</span>, router:<span class="function-name">match</span>(<span class="string">"/users/00000000-0000-0000-0000-000000000000"</span>))</pre> | ||
|
||
|
||
</div> <!-- id="content" --> | ||
</div> <!-- id="main" --> | ||
<div id="about"> | ||
<i>generated by <a href="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i> | ||
<i style="float:right;">Last updated 2024-03-01 01:33:25 </i> | ||
</div> <!-- id="about" --> | ||
</div> <!-- id="container" --> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
local Router = require "radix-router" | ||
local router, err = Router.new({ | ||
{ | ||
paths = { "/users/{id:\\d+}/profile-{year:\\d{4}}.{format:(html|pdf)}" }, | ||
handler = "1" | ||
}, | ||
{ | ||
paths = { "/users/{uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}}" }, | ||
handler = "2" | ||
}, | ||
}) | ||
if not router then | ||
error("failed to create router: " .. err) | ||
end | ||
|
||
assert("1" == router:match("/users/100/profile-2024.pdf")) | ||
assert("2", router:match("/users/00000000-0000-0000-0000-000000000000")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ description = { | |
} | ||
|
||
dependencies = { | ||
"lua >= 5.1, < 5.5" | ||
"lrexlib-pcre2", | ||
} | ||
|
||
build = { | ||
|
Oops, something went wrong.