mirror of
https://github.com/zigzap/zap.git
synced 2025-10-20 15:14:08 +00:00
housekeeping
This commit is contained in:
parent
17d72e1b78
commit
b197fb5ff7
4 changed files with 19 additions and 7 deletions
|
@ -28,6 +28,10 @@ pub fn init(
|
|||
};
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Self) void {
|
||||
self.users.deinit();
|
||||
}
|
||||
|
||||
pub fn getUsers(self: *Self) *Users {
|
||||
return &self.users;
|
||||
}
|
||||
|
|
|
@ -20,8 +20,10 @@ pub fn main() !void {
|
|||
.max_body_size = 100 * 1024 * 1024,
|
||||
},
|
||||
);
|
||||
defer listener.deinit();
|
||||
|
||||
var endpoint = Endpoint.init(allocator, "/users");
|
||||
defer endpoint.deinit();
|
||||
|
||||
// add endpoint
|
||||
try listener.addEndpoint(endpoint.getUserEndpoint());
|
||||
|
|
|
@ -29,6 +29,10 @@ pub fn init(a: std.mem.Allocator) Self {
|
|||
};
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Self) void {
|
||||
self.users.deinit();
|
||||
}
|
||||
|
||||
// the request will be freed (and its mem reused by facilio) when it's
|
||||
// completed, so we take copies of the names
|
||||
pub fn addByName(self: *Self, first: ?[]const u8, last: ?[]const u8) !usize {
|
||||
|
|
|
@ -160,9 +160,6 @@ pub const EndpointListenerError = error{
|
|||
EndpointPathShadowError,
|
||||
};
|
||||
|
||||
// var endpoints: std.StringHashMap(*SimpleEndpoint) = undefined;
|
||||
var endpoints: std.ArrayList(*SimpleEndpoint) = undefined;
|
||||
|
||||
// NOTE: We switch on path.startsWith -> so use endpoints with distinctly
|
||||
// starting names!!
|
||||
pub const SimpleEndpointListener = struct {
|
||||
|
@ -171,10 +168,15 @@ pub const SimpleEndpointListener = struct {
|
|||
|
||||
const Self = @This();
|
||||
|
||||
/// static struct member endpoints
|
||||
var endpoints: std.ArrayList(*SimpleEndpoint) = undefined;
|
||||
|
||||
pub fn init(a: std.mem.Allocator, l: ListenerSettings) Self {
|
||||
var ls = l;
|
||||
ls.on_request = onRequest;
|
||||
endpoints = std.ArrayList(*SimpleEndpoint).init(a);
|
||||
|
||||
var ls = l; // take copy of listener settings
|
||||
ls.on_request = onRequest;
|
||||
|
||||
return .{
|
||||
.listener = Listener.init(ls),
|
||||
.allocator = a,
|
||||
|
@ -186,11 +188,11 @@ pub const SimpleEndpointListener = struct {
|
|||
endpoints.deinit();
|
||||
}
|
||||
|
||||
pub fn listen(self: *SimpleEndpointListener) !void {
|
||||
pub fn listen(self: *Self) !void {
|
||||
try self.listener.listen();
|
||||
}
|
||||
|
||||
pub fn addEndpoint(self: *SimpleEndpointListener, e: *SimpleEndpoint) !void {
|
||||
pub fn addEndpoint(self: *Self, e: *SimpleEndpoint) !void {
|
||||
_ = self;
|
||||
for (endpoints.items) |other| {
|
||||
if (std.mem.startsWith(
|
||||
|
|
Loading…
Add table
Reference in a new issue