feat(routing): support matching key segments in routes
This commit is contained in:
parent
de4e509c9c
commit
f652fa08c1
5 changed files with 207 additions and 39 deletions
|
|
@ -32,6 +32,7 @@ typedef enum lnm_err {
|
|||
lnm_err_not_setup,
|
||||
lnm_err_bad_regex,
|
||||
lnm_err_not_found,
|
||||
lnm_err_already_present,
|
||||
lnm_err_invalid_route,
|
||||
lnm_err_overlapping_route,
|
||||
} lnm_err;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,22 @@
|
|||
#ifndef LNM_HTTP_ROUTER
|
||||
#define LNM_HTTP_ROUTER
|
||||
|
||||
#define LNM_HTTP_MAX_KEY_SEGMENTS 4
|
||||
|
||||
#include "lnm/common.h"
|
||||
#include "lnm/http/consts.h"
|
||||
|
||||
typedef struct lnm_http_route lnm_http_route;
|
||||
|
||||
typedef struct lnm_http_route_match {
|
||||
const lnm_http_route *route;
|
||||
lnm_http_method method;
|
||||
struct {
|
||||
size_t start;
|
||||
size_t len;
|
||||
} key_segments[LNM_HTTP_MAX_KEY_SEGMENTS];
|
||||
} lnm_http_route_match;
|
||||
|
||||
typedef struct lnm_http_router lnm_http_router;
|
||||
|
||||
typedef enum lnm_http_route_err {
|
||||
|
|
@ -31,7 +42,7 @@ lnm_err lnm_http_router_add(lnm_http_route **out, lnm_http_router *http_router,
|
|||
lnm_err lnm_http_router_nest(lnm_http_router *parent,
|
||||
const lnm_http_router *child, const char *prefix);
|
||||
|
||||
lnm_http_route_err lnm_http_router_route(const lnm_http_route **out,
|
||||
lnm_http_route_err lnm_http_router_route(lnm_http_route_match *out,
|
||||
const lnm_http_router *router,
|
||||
lnm_http_method method,
|
||||
const char *path);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue