From ad2b2f2eb034e78e414c5fcdbdc3aa5f38eb2482 Mon Sep 17 00:00:00 2001 From: Rene Schallner Date: Fri, 21 Mar 2025 11:32:27 +0100 Subject: [PATCH] added skeleton for App.zig --- src/App.zig | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/App.zig diff --git a/src/App.zig b/src/App.zig new file mode 100644 index 0000000..317e2ea --- /dev/null +++ b/src/App.zig @@ -0,0 +1,34 @@ +//! WIP: zap.App. +//! +//! - Per Request Arena(s) thread-local? +//! - Custom "State" Context, type-safe +//! - route handlers +//! - automatic error catching & logging, optional report to HTML + +const std = @import("std"); +const zap = @import("zap.zig"); + +pub const Opts = struct { + request_error_strategy: enum { + /// log errors to console + log_to_console, + /// log errors to console AND generate a HTML response + log_to_response, + /// raise errors -> TODO: clarify: where can they be caught? in App.run() + raise, + }, +}; + +threadlocal var arena: ?std.heap.ArenaAllocator = null; + +pub fn create(comptime Context: type, context: *Context, opts: Opts) type { + return struct { + context: *Context = context, + error_strategy: @TypeOf(opts.request_error_strategy) = opts.request_error_strategy, + endpoints: std.StringArrayHashMapUnmanaged(*zap.Endpoint.Wrapper.Internal) = .empty, + + // pub fn addEndpoint(slug: []const u8, endpoint: anytype) !zap.Endpoint { + // // TODO: inspect endpoint: does it have + // } + }; +}