diff --git a/examples/endpoint/stopendpoint.zig b/examples/endpoint/stopendpoint.zig index 9411d49..8ce90d0 100644 --- a/examples/endpoint/stopendpoint.zig +++ b/examples/endpoint/stopendpoint.zig @@ -14,6 +14,7 @@ pub fn init( .ep = zap.Endpoint.init(.{ .path = path, .get = get, + .unset = zap.Endpoint.dummy_handler, }), }; } diff --git a/examples/endpoint_auth/endpoint_auth.zig b/examples/endpoint_auth/endpoint_auth.zig index 4b69d7e..71be399 100644 --- a/examples/endpoint_auth/endpoint_auth.zig +++ b/examples/endpoint_auth/endpoint_auth.zig @@ -42,6 +42,7 @@ pub fn main() !void { .path = "/test", .get = endpoint_http_get, .unauthorized = endpoint_http_unauthorized, + .unset = zap.Endpoint.dummy_handler, }); // create authenticator diff --git a/examples/middleware_with_endpoint/middleware_with_endpoint.zig b/examples/middleware_with_endpoint/middleware_with_endpoint.zig index 3e94450..1b0e5e9 100644 --- a/examples/middleware_with_endpoint/middleware_with_endpoint.zig +++ b/examples/middleware_with_endpoint/middleware_with_endpoint.zig @@ -144,6 +144,7 @@ const HtmlEndpoint = struct { .ep = zap.Endpoint.init(.{ .path = "/doesn't+matter", .get = get, + .unset = zap.Endpoint.dummy_handler, }), }; } diff --git a/src/endpoint.zig b/src/endpoint.zig index c0951b0..3e325f0 100644 --- a/src/endpoint.zig +++ b/src/endpoint.zig @@ -43,20 +43,20 @@ pub fn init(s: Settings) Endpoint { return .{ .settings = .{ .path = s.path, - .get = s.get orelse s.unset orelse &nop, - .post = s.post orelse s.unset orelse &nop, - .put = s.put orelse s.unset orelse &nop, - .delete = s.delete orelse s.unset orelse &nop, - .patch = s.patch orelse s.unset orelse &nop, - .options = s.options orelse s.unset orelse &nop, - .unauthorized = s.unauthorized orelse s.unset orelse &nop, - .unset = s.unset orelse &nop, + .get = s.get orelse s.unset orelse @panic("Endpoint handler `.get` is unset, and no `.unset` handler is provided."), + .post = s.post orelse s.unset orelse @panic("Endpoint handler `.post` is unset, and no `.unset` handler is provided."), + .put = s.put orelse s.unset orelse @panic("Endpoint handler `.put` is unset, and no `.unset` handler is provided."), + .delete = s.delete orelse s.unset orelse @panic("Endpoint handler `.delete` is unset, and no `.unset` handler is provided."), + .patch = s.patch orelse s.unset orelse @panic("Endpoint handler `.patch` is unset, and no `.unset` handler is provided."), + .options = s.options orelse s.unset orelse @panic("Endpoint handler `.options` is unset, and no `.unset` handler is provided."), + .unauthorized = s.unauthorized orelse s.unset orelse @panic("Endpoint handler `.unauthorized` is unset, and no `.unset` handler is provided."), + .unset = s.unset, }, }; } // no operation. Dummy handler function for ignoring unset request types. -fn nop(self: *Endpoint, r: Request) void { +pub fn dummy_handler(self: *Endpoint, r: Request) void { _ = self; _ = r; }