Skip to content

Commit

Permalink
chore: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mookums committed Dec 18, 2024
1 parent 18a2a8d commit d551534
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 28 deletions.
3 changes: 0 additions & 3 deletions examples/basic/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ pub fn main() !void {
\\ </body>
\\ </html>
;

const body = try std.fmt.allocPrint(ctx.allocator, body_fmt, .{ctx.state.*});

// This is the standard response and what you
// will usually be using. This will send to the
// client and then continue to await more requests.
Expand All @@ -63,7 +61,6 @@ pub fn main() !void {
try ctx.allocator.dupe(u8, b)
else
"";

try ctx.respond(.{
.status = .OK,
.mime = http.Mime.HTML,
Expand Down
1 change: 0 additions & 1 deletion examples/fs/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ pub fn main() !void {
\\ </body>
\\ </html>
;

try ctx.respond(.{
.status = .OK,
.mime = http.Mime.HTML,
Expand Down
1 change: 0 additions & 1 deletion examples/minram/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ pub fn main() !void {
\\ </body>
\\ </html>
;

try ctx.respond(.{
.status = .OK,
.mime = http.Mime.HTML,
Expand Down
1 change: 0 additions & 1 deletion examples/tls/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ pub fn main() !void {
\\ </body>
\\ </html>
;

try ctx.respond(.{
.status = .OK,
.mime = http.Mime.HTML,
Expand Down
4 changes: 1 addition & 3 deletions examples/unix/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ pub fn main() !void {
});
defer t.deinit();

var router = Router.init({}, &[_]Route{
Route.init("/").get(root_handler)
}, .{});
var router = Router.init({}, &[_]Route{Route.init("/").get(root_handler)}, .{});

try t.entry(
&router,
Expand Down
3 changes: 1 addition & 2 deletions examples/valgrind/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ pub fn main() !void {
\\ </body>
\\ </html>
;

try ctx.respond(.{
.status = .OK,
.mime = http.Mime.HTML,
Expand All @@ -44,7 +43,7 @@ pub fn main() !void {
pub fn handler_fn(ctx: *Context) !void {
ctx.runtime.stop();
}
}.handler_fn)
}.handler_fn),
}, .{});

var t = try Tardy.init(.{
Expand Down
2 changes: 1 addition & 1 deletion src/http/router/fs_dir.zig
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ pub fn FsDir(Server: type, AppState: type) type {

//TODO Can we do this once and for all at initialization?
// Resolving the base directory.
const resolved_dir = try std.fs.path.resolve(ctx.allocator, &[_][]const u8{ dir_path });
const resolved_dir = try std.fs.path.resolve(ctx.allocator, &[_][]const u8{dir_path});
defer ctx.allocator.free(resolved_dir);

// Resolving the requested file.
Expand Down
12 changes: 6 additions & 6 deletions src/http/router/route.zig
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,14 @@ pub fn Route(comptime Server: type, comptime AppState: type) type {
);

return self
// Set the new path.
// Set the new path.
.set_path(url_with_match_all)
// Set GET handler.
// Set GET handler.
.get(struct {
fn handler_fn(ctx: *Context) !void {
try FsDir.handler_fn(ctx, dir_path);
}
}.handler_fn);
fn handler_fn(ctx: *Context) !void {
try FsDir.handler_fn(ctx, dir_path);
}
}.handler_fn);
}
};
}
7 changes: 1 addition & 6 deletions src/http/router/routing_trie.zig
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ pub fn RoutingTrie(comptime Server: type, comptime AppState: type) type {

/// Initialize a cloned node with a new child for the provided token.
pub fn with_child(self: *const Node, token: Token, node: *const Node) Node {
return Node{
.token = self.token,
.route = self.route,
.children = self.children.with_kvs(&[_]ChildrenMap.KV{.{ token, node }})
};
return Node{ .token = self.token, .route = self.route, .children = self.children.with_kvs(&[_]ChildrenMap.KV{.{ token, node }}) };
}
};

Expand Down Expand Up @@ -136,7 +132,6 @@ pub fn RoutingTrie(comptime Server: type, comptime AppState: type) type {
}
std.debug.print("\n", .{});


print_node(node, depth + 1);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/http/router/token_hash_map.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ const std = @import("std");
const Token = @import("routing_trie.zig").Token;

/// Errors of get function.
pub const MapGetErrors = error {
pub const MapGetErrors = error{
NotFound,
};

/// Type of a token hash.
pub const Hash = u64;

/// Type of a hash entry in hashed array.
pub const HashEntry = struct{Hash, usize};
pub const HashEntry = struct { Hash, usize };

/// In-place sort of the given array at compile time.
/// Implementation reference: https://github.com/Koura/algorithms/blob/b1dd07147a34554543994b2c033fae64a2202933/sorting/quicksort.zig
Expand Down Expand Up @@ -111,7 +111,7 @@ pub fn TokenHashMap(V: type) type {
pub fn get_kvs(self: *const Self) []const KV {
var kvs: [self.keys.len]KV = undefined;
for (&kvs, self.keys, self.values) |*kv, key, value| {
kv.* = .{key, value};
kv.* = .{ key, value };
}
return &kvs;
}
Expand Down Expand Up @@ -160,7 +160,7 @@ pub fn TokenHashMap(V: type) type {

// Search in the sorted hashes array.
const hash_index = std.sort.binarySearch(HashEntry, hash, self.hashes, {}, struct {
fn f (_: void, searched_key: Hash, mid_item: HashEntry) std.math.Order {
fn f(_: void, searched_key: Hash, mid_item: HashEntry) std.math.Order {
if (searched_key < mid_item[0]) return std.math.Order.lt;
if (searched_key > mid_item[0]) return std.math.Order.gt;
if (searched_key == mid_item[0]) return std.math.Order.eq;
Expand Down

0 comments on commit d551534

Please sign in to comment.