feat(routing): support matching key segments in routes

This commit is contained in:
Jef Roosens 2024-02-22 22:15:19 +01:00
parent de4e509c9c
commit f652fa08c1
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
5 changed files with 207 additions and 39 deletions

View file

@ -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;

View file

@ -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);