1 ed8cff62 2023-12-21 op // This is free and unencumbered software released into the public domain.
3 ed8cff62 2023-12-21 op // Anyone is free to copy, modify, publish, use, compile, sell, or
4 ed8cff62 2023-12-21 op // distribute this software, either in source code form or as a compiled
5 ed8cff62 2023-12-21 op // binary, for any purpose, commercial or non-commercial, and by any
8 ed8cff62 2023-12-21 op // In jurisdictions that recognize copyright laws, the author or authors
9 ed8cff62 2023-12-21 op // of this software dedicate any and all copyright interest in the
10 ed8cff62 2023-12-21 op // software to the public domain. We make this dedication for the benefit
11 ed8cff62 2023-12-21 op // of the public at large and to the detriment of our heirs and
12 ed8cff62 2023-12-21 op // successors. We intend this dedication to be an overt act of
13 ed8cff62 2023-12-21 op // relinquishment in perpetuity of all present and future rights to this
14 ed8cff62 2023-12-21 op // software under copyright law.
16 ed8cff62 2023-12-21 op // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 ed8cff62 2023-12-21 op // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 ed8cff62 2023-12-21 op // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 ed8cff62 2023-12-21 op // IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 ed8cff62 2023-12-21 op // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 ed8cff62 2023-12-21 op // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 ed8cff62 2023-12-21 op // OTHER DEALINGS IN THE SOFTWARE.
26 ed8cff62 2023-12-21 op export type route = struct {
28 ed8cff62 2023-12-21 op routefn: routefn,
31 ed8cff62 2023-12-21 op export type mux = []route;
33 ed8cff62 2023-12-21 op let global: mux = [];
35 ed8cff62 2023-12-21 op export fn newmux() mux = [];
37 ed8cff62 2023-12-21 op export fn handle(pattern: str, routefn: routefn) void = {
38 ed8cff62 2023-12-21 op handle_mux(&global, pattern, routefn);
41 ed8cff62 2023-12-21 op export fn handle_mux(mux: *mux, pattern: str, routefn: routefn) void = {
42 ed8cff62 2023-12-21 op append(mux, route {
43 ed8cff62 2023-12-21 op pattern = pattern,
44 ed8cff62 2023-12-21 op routefn = routefn,
48 ed8cff62 2023-12-21 op export fn mux_match(mux: *mux, req: *request, default: routefn) routefn = {
49 ed8cff62 2023-12-21 op for (let i = 0z; i < len(mux); i += 1) {
50 ed8cff62 2023-12-21 op if (fnmatch::fnmatch(mux[i].pattern, req.path)) {
51 ed8cff62 2023-12-21 op return mux[i].routefn;
55 ed8cff62 2023-12-21 op return default;