Skip to content

Commit

Permalink
add node on middleware thread-safety
Browse files Browse the repository at this point in the history
  • Loading branch information
karlseguin committed Aug 16, 2024
1 parent 4a7b9f7 commit c8bd02d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions example/middleware/Logger.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ const Logger = @This();

query: bool,

// Must define an `init` method, which will accept your Congi
// Must define an `init` method, which will accept your Congif
pub fn init(config: Config) Logger {
return .{
.query = config.query,
};
}

// Must define an `execute` method. `self` doesn't have to be `const`, but
// you're responsible for making your middleware thread-safe.
pub fn execute(self: *const Logger, req: *httpz.Request, res: *httpz.Response, executor: anytype) !void {
// generally better to use an std.time.Timer to measure elapsed time
// Better to use an std.time.Timer to measure elapsed time
// but we need the "start" time for our log anyways, so while this might occasionally
// report wrong/strange "elapsed" time, it's simpler to do.
const start = std.time.microTimestamp();
Expand Down

0 comments on commit c8bd02d

Please sign in to comment.