diff --git a/src/http/middleware.zig b/src/http/middleware.zig index 9e8ce1b..7f4e5f6 100644 --- a/src/http/middleware.zig +++ b/src/http/middleware.zig @@ -176,6 +176,14 @@ pub fn Router(comptime Routes: []const type) type { } }; } +fn fieldTypes(comptime Tuple: type) []const type { + var types: [Tuple.len]type = undefined; + for (std.meta.fields(Tuple)) |f, i| types[i] = f.field_type; + return &types; +} +pub fn router(routes: anytype) Router(fieldTypes(@TypeOf(routes))) { + return Router(fieldTypes(@TypeOf(routes))){ .routes = routes }; +} // helper function for doing route analysis fn pathMatches(route: []const u8, path: []const u8) bool { @@ -219,14 +227,6 @@ pub const Route = struct { error.RouteMismatch; } }; -pub fn ComptimeRoute(comptime desc: Route.Desc) type { - return struct { - const route = Route{ .desc = desc }; - pub fn handle(_: @This(), req: anytype, res: anytype, ctx: anytype, next: anytype) !void { - return route.handle(req, res, ctx, next); - } - }; -} pub fn Mount(comptime route: []const u8) type { return struct {