1
0
Fork 0
mirror of https://github.com/zigzap/zap.git synced 2025-10-20 23:24:09 +00:00

add mandatory handlers

This commit is contained in:
OsakiTsukiko 2024-10-28 09:37:42 +02:00
parent 15ba95ee07
commit 789d876ba7
4 changed files with 12 additions and 9 deletions

View file

@ -14,6 +14,7 @@ pub fn init(
.ep = zap.Endpoint.init(.{
.path = path,
.get = get,
.unset = zap.Endpoint.dummy_handler,
}),
};
}

View file

@ -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

View file

@ -144,6 +144,7 @@ const HtmlEndpoint = struct {
.ep = zap.Endpoint.init(.{
.path = "/doesn't+matter",
.get = get,
.unset = zap.Endpoint.dummy_handler,
}),
};
}

View file

@ -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;
}