mirror of
https://github.com/zigzap/zap.git
synced 2025-10-20 15:14:08 +00:00
fix router.zig type checking, remove wrk examples from build.zig
This commit is contained in:
parent
75c0cfdf02
commit
43c411dcd7
2 changed files with 12 additions and 8 deletions
|
@ -60,8 +60,6 @@ pub fn build(b: *std.Build) !void {
|
|||
.{ .name = "serve", .src = "examples/serve/serve.zig" },
|
||||
.{ .name = "hello_json", .src = "examples/hello_json/hello_json.zig" },
|
||||
.{ .name = "endpoint", .src = "examples/endpoint/main.zig" },
|
||||
.{ .name = "wrk", .src = "wrk/zig/main.zig" },
|
||||
.{ .name = "wrk_zigstd", .src = "wrk/zigstd/main.zig" },
|
||||
.{ .name = "mustache", .src = "examples/mustache/mustache.zig" },
|
||||
.{ .name = "endpoint_auth", .src = "examples/endpoint_auth/endpoint_auth.zig" },
|
||||
.{ .name = "http_params", .src = "examples/http_params/http_params.zig" },
|
||||
|
|
|
@ -82,10 +82,10 @@ pub fn handle_func(self: *Router, path: []const u8, instance: *anyopaque, handle
|
|||
// Need to check:
|
||||
// 1) handler is function pointer
|
||||
const f = blk: {
|
||||
if (hand_info == .Pointer) {
|
||||
const inner = @typeInfo(hand_info.Pointer.child);
|
||||
if (inner == .Fn) {
|
||||
break :blk inner.Fn;
|
||||
if (hand_info == .pointer) {
|
||||
const inner = @typeInfo(hand_info.pointer.child);
|
||||
if (inner == .@"fn") {
|
||||
break :blk inner.@"fn";
|
||||
}
|
||||
}
|
||||
@compileError("Expected handler to be a function pointer. Found " ++
|
||||
|
@ -104,8 +104,14 @@ pub fn handle_func(self: *Router, path: []const u8, instance: *anyopaque, handle
|
|||
|
||||
// 3) handler returns void
|
||||
const ret_info = @typeInfo(f.return_type.?);
|
||||
if (ret_info != .Void) {
|
||||
@compileError("Expected handler's return type to be void. Found " ++
|
||||
if (ret_info != .error_union) {
|
||||
@compileError("Expected handler's return type to be !void. Found " ++
|
||||
@typeName(f.return_type.?));
|
||||
}
|
||||
|
||||
const payload = @typeInfo(ret_info.error_union.payload);
|
||||
if (payload != .void) {
|
||||
@compileError("Expected handler's return type to be !void. Found " ++
|
||||
@typeName(f.return_type.?));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue