mirror of
https://github.com/zigzap/zap.git
synced 2025-10-21 07:34: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(.{
|
.ep = zap.Endpoint.init(.{
|
||||||
.path = path,
|
.path = path,
|
||||||
.get = get,
|
.get = get,
|
||||||
|
.unset = zap.Endpoint.dummy_handler,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ pub fn main() !void {
|
||||||
.path = "/test",
|
.path = "/test",
|
||||||
.get = endpoint_http_get,
|
.get = endpoint_http_get,
|
||||||
.unauthorized = endpoint_http_unauthorized,
|
.unauthorized = endpoint_http_unauthorized,
|
||||||
|
.unset = zap.Endpoint.dummy_handler,
|
||||||
});
|
});
|
||||||
|
|
||||||
// create authenticator
|
// create authenticator
|
||||||
|
|
|
@ -144,6 +144,7 @@ const HtmlEndpoint = struct {
|
||||||
.ep = zap.Endpoint.init(.{
|
.ep = zap.Endpoint.init(.{
|
||||||
.path = "/doesn't+matter",
|
.path = "/doesn't+matter",
|
||||||
.get = get,
|
.get = get,
|
||||||
|
.unset = zap.Endpoint.dummy_handler,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,20 +43,20 @@ pub fn init(s: Settings) Endpoint {
|
||||||
return .{
|
return .{
|
||||||
.settings = .{
|
.settings = .{
|
||||||
.path = s.path,
|
.path = s.path,
|
||||||
.get = s.get orelse 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 &nop,
|
.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 &nop,
|
.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 &nop,
|
.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 &nop,
|
.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 &nop,
|
.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 &nop,
|
.unauthorized = s.unauthorized orelse s.unset orelse @panic("Endpoint handler `.unauthorized` is unset, and no `.unset` handler is provided."),
|
||||||
.unset = s.unset orelse &nop,
|
.unset = s.unset,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// no operation. Dummy handler function for ignoring unset request types.
|
// 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;
|
_ = self;
|
||||||
_ = r;
|
_ = r;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue