mirror of
https://github.com/zigzap/zap.git
synced 2025-10-20 15:14:08 +00:00
add mandatory handlers
This commit is contained in:
parent
15ba95ee07
commit
789d876ba7
4 changed files with 12 additions and 9 deletions
|
@ -14,6 +14,7 @@ pub fn init(
|
|||
.ep = zap.Endpoint.init(.{
|
||||
.path = path,
|
||||
.get = get,
|
||||
.unset = zap.Endpoint.dummy_handler,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -144,6 +144,7 @@ const HtmlEndpoint = struct {
|
|||
.ep = zap.Endpoint.init(.{
|
||||
.path = "/doesn't+matter",
|
||||
.get = get,
|
||||
.unset = zap.Endpoint.dummy_handler,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue