Remove circular dependency

This commit is contained in:
jaina heartles 2022-04-23 03:18:46 -07:00
parent 6a37685643
commit 4d18f031a8
2 changed files with 5 additions and 5 deletions

View file

@ -21,8 +21,8 @@ pub const routes = [_]Route{
const this_scheme = "http"; const this_scheme = "http";
const this_host = "localhost:8080"; const this_host = "localhost:8080";
fn getUser(ctx: *http.Context) anyerror!void { fn getUser(ctx: *http.Context, route: *const router.Route) anyerror!void {
const id_str = ctx.request.arg("id"); const id_str = route.arg("id", ctx.request.path);
const host = ctx.request.headers.get("host") orelse { const host = ctx.request.headers.get("host") orelse {
try ctx.response.statusOnly(400); try ctx.response.statusOnly(400);
@ -52,7 +52,7 @@ fn getUser(ctx: *http.Context) anyerror!void {
fn staticString(comptime str: []const u8) Route.Handler { fn staticString(comptime str: []const u8) Route.Handler {
return (struct { return (struct {
fn func(ctx: *http.Context) anyerror!void { fn func(ctx: *http.Context, _: *const router.Route) anyerror!void {
try ctx.response.headers.put("Content-Type", "text/plain"); try ctx.response.headers.put("Content-Type", "text/plain");
try ctx.response.write(200, str); try ctx.response.write(200, str);
} }

View file

@ -11,7 +11,7 @@ pub const Route = struct {
literal: []const u8, literal: []const u8,
}; };
pub const Handler = fn (*Context) callconv(.Async) anyerror!void; pub const Handler = fn (*Context, *const Route) callconv(.Async) anyerror!void;
fn normalize(comptime path: []const u8) []const u8 { fn normalize(comptime path: []const u8) []const u8 {
var arr: [path.len]u8 = undefined; var arr: [path.len]u8 = undefined;
@ -159,7 +159,7 @@ pub fn routeRequest(ctx: *Context) !void {
var buf = try ctx.allocator.allocWithOptions(u8, @frameSize(route.handler), 8, null); var buf = try ctx.allocator.allocWithOptions(u8, @frameSize(route.handler), 8, null);
defer ctx.allocator.free(buf); defer ctx.allocator.free(buf);
return await @asyncCall(buf, {}, route.handler, .{ctx}); return await @asyncCall(buf, {}, route.handler, .{ ctx, route });
} }
} }