1
0
Fork 0
mirror of https://github.com/zigzap/zap.git synced 2025-10-20 15:14:08 +00:00

Merge branch 'master' into appsperiments

This commit is contained in:
Rene Schallner 2025-03-30 13:20:06 +02:00 committed by GitHub
commit 5a62a5dbac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 1 deletions

View file

@ -96,7 +96,7 @@ void free_ws_buffer(ws_s *owner, struct buffer_s buff) {
Create/Destroy the websocket object (prototypes) Create/Destroy the websocket object (prototypes)
*/ */
static ws_s *new_websocket(); static ws_s *new_websocket(intptr_t uuid);
static void destroy_ws(ws_s *ws); static void destroy_ws(ws_s *ws);
/******************************************************************************* /*******************************************************************************

View file

@ -75,6 +75,41 @@ pub fn handle_func_unbound(self: *Router, path: []const u8, h: zap.HttpRequestFn
pub fn handle_func(self: *Router, path: []const u8, instance: *anyopaque, handler: anytype) !void { pub fn handle_func(self: *Router, path: []const u8, instance: *anyopaque, handler: anytype) !void {
// TODO: assert type of instance has handler // TODO: assert type of instance has handler
// Introspection checks on handler type
comptime {
const hand_info = @typeInfo(@TypeOf(handler));
// 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;
}
}
@compileError("Expected handler to be a function pointer. Found " ++
@typeName(@TypeOf(handler)));
};
// 2) snd arg is zap.Request
if (f.params.len != 2) {
@compileError("Expected handler to have two paramters");
}
const arg_type = f.params[1].type.?;
if (arg_type != zap.Request) {
@compileError("Expected handler's second argument to be of type zap.Request. Found " ++
@typeName(arg_type));
}
// 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 " ++
@typeName(f.return_type.?));
}
}
if (path.len == 0) { if (path.len == 0) {
return RouterError.EmptyPath; return RouterError.EmptyPath;
} }