mirror of
https://github.com/zigzap/zap.git
synced 2025-10-21 15:44:10 +00:00
restore lost changes
This commit is contained in:
parent
8654ad8310
commit
51d17a1868
2 changed files with 117 additions and 115 deletions
34
src/App.zig
34
src/App.zig
|
@ -32,7 +32,7 @@ pub fn Create(comptime Context: type) type {
|
||||||
context: *Context = undefined,
|
context: *Context = undefined,
|
||||||
gpa: Allocator = undefined,
|
gpa: Allocator = undefined,
|
||||||
opts: Opts = undefined,
|
opts: Opts = undefined,
|
||||||
endpoints: std.StringArrayHashMapUnmanaged(*Endpoint.Wrapper.Interface) = .empty,
|
endpoints: std.StringArrayHashMapUnmanaged(*Endpoint.Interface) = .empty,
|
||||||
|
|
||||||
there_can_be_only_one: bool = false,
|
there_can_be_only_one: bool = false,
|
||||||
track_arenas: std.ArrayListUnmanaged(*ArenaAllocator) = .empty,
|
track_arenas: std.ArrayListUnmanaged(*ArenaAllocator) = .empty,
|
||||||
|
@ -46,7 +46,6 @@ pub fn Create(comptime Context: type) type {
|
||||||
var on_request: ?*const fn (Allocator, *Context, Request) anyerror!void = null;
|
var on_request: ?*const fn (Allocator, *Context, Request) anyerror!void = null;
|
||||||
|
|
||||||
pub const Endpoint = struct {
|
pub const Endpoint = struct {
|
||||||
pub const Wrapper = struct {
|
|
||||||
pub const Interface = struct {
|
pub const Interface = struct {
|
||||||
call: *const fn (*Interface, zap.Request) anyerror!void = undefined,
|
call: *const fn (*Interface, zap.Request) anyerror!void = undefined,
|
||||||
path: []const u8,
|
path: []const u8,
|
||||||
|
@ -101,16 +100,16 @@ pub fn Create(comptime Context: type) type {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(T: type, value: *T, app_opts: Opts, app_context: *Context) Wrapper.Wrap(T) {
|
pub fn init(T: type, value: *T, app_opts: Opts, app_context: *Context) Endpoint.Wrap(T) {
|
||||||
checkEndpointType(T);
|
checkEndpointType(T);
|
||||||
var ret: Wrapper.Wrap(T) = .{
|
var ret: Endpoint.Wrap(T) = .{
|
||||||
.wrapped = value,
|
.wrapped = value,
|
||||||
.wrapper = .{ .path = value.path },
|
.wrapper = .{ .path = value.path },
|
||||||
.opts = app_opts,
|
.opts = app_opts,
|
||||||
.app_context = app_context,
|
.app_context = app_context,
|
||||||
};
|
};
|
||||||
ret.wrapper.call = Wrapper.Wrap(T).onRequestWrapped;
|
ret.wrapper.call = Endpoint.Wrap(T).onRequestWrapped;
|
||||||
ret.wrapper.destroy = Wrapper.Wrap(T).destroy;
|
ret.wrapper.destroy = Endpoint.Wrap(T).destroy;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,12 +149,15 @@ pub fn Create(comptime Context: type) type {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
pub const Listener = struct {
|
pub const ListenerSettings = struct {
|
||||||
pub const Settings = struct {
|
port: usize,
|
||||||
//
|
interface: [*c]const u8 = null,
|
||||||
};
|
public_folder: ?[]const u8 = null,
|
||||||
|
max_clients: ?isize = null,
|
||||||
|
max_body_size: ?usize = null,
|
||||||
|
timeout: ?u8 = null,
|
||||||
|
tls: ?zap.Tls = null,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn init(gpa_: Allocator, context_: *Context, opts_: Opts) !App {
|
pub fn init(gpa_: Allocator, context_: *Context, opts_: Opts) !App {
|
||||||
|
@ -208,17 +210,17 @@ pub fn Create(comptime Context: type) type {
|
||||||
endpoint.path,
|
endpoint.path,
|
||||||
other.path,
|
other.path,
|
||||||
)) {
|
)) {
|
||||||
return zap.Endpoint.EndpointListenerError.EndpointPathShadowError;
|
return zap.Endpoint.ListenerError.EndpointPathShadowError;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const EndpointType = @typeInfo(@TypeOf(endpoint)).pointer.child;
|
const EndpointType = @typeInfo(@TypeOf(endpoint)).pointer.child;
|
||||||
Endpoint.Wrapper.checkEndpointType(EndpointType);
|
Endpoint.checkEndpointType(EndpointType);
|
||||||
const wrapper = try self.gpa.create(Endpoint.Wrapper.Wrap(EndpointType));
|
const wrapper = try self.gpa.create(Endpoint.Wrap(EndpointType));
|
||||||
wrapper.* = Endpoint.Wrapper.init(EndpointType, endpoint);
|
wrapper.* = Endpoint.init(EndpointType, endpoint);
|
||||||
try App._static.endpoints.append(self.gpa, &wrapper.wrapper);
|
try App._static.endpoints.append(self.gpa, &wrapper.wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn listen(self: *App, l: Listener.Settings) !void {
|
pub fn listen(self: *App, l: ListenerSettings) !void {
|
||||||
_ = self;
|
_ = self;
|
||||||
_ = l;
|
_ = l;
|
||||||
// TODO: do it
|
// TODO: do it
|
||||||
|
|
|
@ -246,7 +246,7 @@ pub fn Authenticating(EndpointType: type, Authenticator: type) type {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const EndpointListenerError = error{
|
pub const ListenerError = error{
|
||||||
/// Since we use .startsWith to check for matching paths, you cannot use
|
/// Since we use .startsWith to check for matching paths, you cannot use
|
||||||
/// endpoint paths that overlap at the beginning. --> When trying to register
|
/// endpoint paths that overlap at the beginning. --> When trying to register
|
||||||
/// an endpoint whose path would shadow an already registered one, you will
|
/// an endpoint whose path would shadow an already registered one, you will
|
||||||
|
@ -323,7 +323,7 @@ pub const Listener = struct {
|
||||||
e.path,
|
e.path,
|
||||||
other.path,
|
other.path,
|
||||||
)) {
|
)) {
|
||||||
return EndpointListenerError.EndpointPathShadowError;
|
return ListenerError.EndpointPathShadowError;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const EndpointType = @typeInfo(@TypeOf(e)).pointer.child;
|
const EndpointType = @typeInfo(@TypeOf(e)).pointer.child;
|
||||||
|
|
Loading…
Add table
Reference in a new issue