mirror of
https://github.com/zigzap/zap.git
synced 2025-10-21 07:34:08 +00:00
Plow through all remaining zig-0.12-dev updates 😵
This commit is contained in:
parent
da420b4114
commit
885db6aacf
9 changed files with 42 additions and 46 deletions
|
@ -16,7 +16,7 @@ const Handler = struct {
|
|||
// check for query params (for ?terminate=true)
|
||||
r.parseQuery();
|
||||
|
||||
var param_count = r.getParamCount();
|
||||
const param_count = r.getParamCount();
|
||||
std.log.info("param_count: {}", .{param_count});
|
||||
|
||||
// iterate over all params
|
||||
|
@ -28,7 +28,8 @@ const Handler = struct {
|
|||
for (params.items) |kv| {
|
||||
if (kv.value) |v| {
|
||||
std.debug.print("\n", .{});
|
||||
std.log.info("Param `{s}` in owned list is {any}\n", .{ kv.key.str, v });
|
||||
// TODO: Zig fails to format 'v':
|
||||
// std.log.info("Param `{s}` in owned list is {any}\n", .{ kv.key.str, v });
|
||||
switch (v) {
|
||||
// single-file upload
|
||||
zap.Request.HttpParam.Hash_Binfile => |*file| {
|
||||
|
@ -87,7 +88,7 @@ pub fn main() !void {
|
|||
var gpa = std.heap.GeneralPurposeAllocator(.{
|
||||
.thread_safe = true,
|
||||
}){};
|
||||
var allocator = gpa.allocator();
|
||||
const allocator = gpa.allocator();
|
||||
|
||||
Handler.alloc = allocator;
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ fn setupUserData(a: std.mem.Allocator) !void {
|
|||
}
|
||||
|
||||
pub fn main() !void {
|
||||
var a = std.heap.page_allocator;
|
||||
const a = std.heap.page_allocator;
|
||||
try setupUserData(a);
|
||||
var listener = zap.HttpListener.init(.{
|
||||
.port = 3000,
|
||||
|
|
|
@ -61,9 +61,10 @@ pub fn main() !void {
|
|||
// iterate over all params
|
||||
const params = r.parametersToOwnedList(alloc, false) catch unreachable;
|
||||
defer params.deinit();
|
||||
for (params.items) |kv| {
|
||||
std.log.info("Param `{s}` is {any}", .{ kv.key.str, kv.value });
|
||||
}
|
||||
// for (params.items) |kv| {
|
||||
// // TODO: fmt can't format kv.value
|
||||
// // std.log.info("Param `{s}` is {any}", .{ kv.key.str, kv.value.? });
|
||||
// }
|
||||
|
||||
// let's get param "one" by name
|
||||
std.debug.print("\n", .{});
|
||||
|
|
|
@ -71,9 +71,8 @@ const UserMiddleWare = struct {
|
|||
// note that the first parameter is of type *Handler, not *Self !!!
|
||||
pub fn onRequest(handler: *Handler, r: zap.Request, context: *Context) bool {
|
||||
|
||||
// this is how we would get our self pointer
|
||||
var self = @fieldParentPtr(Self, "handler", handler);
|
||||
_ = self;
|
||||
// this is how we would get our self pointer:
|
||||
// var self = @fieldParentPtr(Self, "handler", handler);
|
||||
|
||||
// do our work: fill in the user field of the context
|
||||
context.user = User{
|
||||
|
@ -114,9 +113,8 @@ const SessionMiddleWare = struct {
|
|||
|
||||
// note that the first parameter is of type *Handler, not *Self !!!
|
||||
pub fn onRequest(handler: *Handler, r: zap.Request, context: *Context) bool {
|
||||
// this is how we would get our self pointer
|
||||
var self = @fieldParentPtr(Self, "handler", handler);
|
||||
_ = self;
|
||||
// this is how we would get our self pointer:
|
||||
// var self = @fieldParentPtr(Self, "handler", handler);
|
||||
|
||||
context.session = Session{
|
||||
.info = "secret session",
|
||||
|
@ -149,10 +147,10 @@ const HtmlMiddleWare = struct {
|
|||
|
||||
// note that the first parameter is of type *Handler, not *Self !!!
|
||||
pub fn onRequest(handler: *Handler, r: zap.Request, context: *Context) bool {
|
||||
_ = handler;
|
||||
|
||||
// this is how we would get our self pointer
|
||||
var self = @fieldParentPtr(Self, "handler", handler);
|
||||
_ = self;
|
||||
// this is how we would get our self pointer:
|
||||
// var self = @fieldParentPtr(Self, "handler", handler);
|
||||
|
||||
std.debug.print("\n\nHtmlMiddleware: handling request with context: {any}\n\n", .{context});
|
||||
|
||||
|
@ -190,7 +188,7 @@ pub fn main() !void {
|
|||
var gpa = std.heap.GeneralPurposeAllocator(.{
|
||||
.thread_safe = true,
|
||||
}){};
|
||||
var allocator = gpa.allocator();
|
||||
const allocator = gpa.allocator();
|
||||
SharedAllocator.init(allocator);
|
||||
|
||||
// we create our HTML middleware component that handles the request
|
||||
|
|
|
@ -59,9 +59,8 @@ const UserMiddleWare = struct {
|
|||
// note that the first parameter is of type *Handler, not *Self !!!
|
||||
pub fn onRequest(handler: *Handler, r: zap.Request, context: *Context) bool {
|
||||
|
||||
// this is how we would get our self pointer
|
||||
var self = @fieldParentPtr(Self, "handler", handler);
|
||||
_ = self;
|
||||
// this is how we would get our self pointer:
|
||||
// var self = @fieldParentPtr(Self, "handler", handler);
|
||||
|
||||
// do our work: fill in the user field of the context
|
||||
context.user = User{
|
||||
|
@ -104,9 +103,8 @@ const SessionMiddleWare = struct {
|
|||
|
||||
// note that the first parameter is of type *Handler, not *Self !!!
|
||||
pub fn onRequest(handler: *Handler, r: zap.Request, context: *Context) bool {
|
||||
// this is how we would get our self pointer
|
||||
var self = @fieldParentPtr(Self, "handler", handler);
|
||||
_ = self;
|
||||
// this is how we would get our self pointer:
|
||||
// var self = @fieldParentPtr(Self, "handler", handler);
|
||||
|
||||
context.session = Session{
|
||||
.info = "secret session",
|
||||
|
@ -200,7 +198,7 @@ pub fn main() !void {
|
|||
var gpa = std.heap.GeneralPurposeAllocator(.{
|
||||
.thread_safe = true,
|
||||
}){};
|
||||
var allocator = gpa.allocator();
|
||||
const allocator = gpa.allocator();
|
||||
SharedAllocator.init(allocator);
|
||||
|
||||
// create the endpoint
|
||||
|
|
|
@ -73,7 +73,7 @@ pub fn main() !void {
|
|||
var gpa = std.heap.GeneralPurposeAllocator(.{
|
||||
.thread_safe = true,
|
||||
}){};
|
||||
var allocator = gpa.allocator();
|
||||
const allocator = gpa.allocator();
|
||||
|
||||
var simpleRouter = zap.Router.init(allocator, .{
|
||||
.not_found = not_found,
|
||||
|
|
|
@ -88,7 +88,7 @@ fn get_tag_annotation(allocator: std.mem.Allocator, tagname: []const u8) ![]cons
|
|||
tagname,
|
||||
};
|
||||
|
||||
const result = try std.ChildProcess.exec(.{
|
||||
const result = try std.ChildProcess.run(.{
|
||||
.allocator = allocator,
|
||||
.argv = &args,
|
||||
});
|
||||
|
@ -161,13 +161,13 @@ fn sendToDiscordPart(allocator: std.mem.Allocator, url: []const u8, message_json
|
|||
defer http_client.deinit();
|
||||
|
||||
// request
|
||||
var req = try http_client.request(.POST, uri, h, .{});
|
||||
var req = try http_client.open(.POST, uri, h, .{});
|
||||
defer req.deinit();
|
||||
|
||||
req.transfer_encoding = .chunked;
|
||||
|
||||
// connect, send request
|
||||
try req.start();
|
||||
try req.send(.{ .raw_uri = false });
|
||||
|
||||
// send POST payload
|
||||
try req.writer().writeAll(message_json);
|
||||
|
@ -182,7 +182,7 @@ fn sendToDiscordPart(allocator: std.mem.Allocator, url: []const u8, message_json
|
|||
fn sendToDiscord(allocator: std.mem.Allocator, url: []const u8, message: []const u8) !void {
|
||||
// json payload
|
||||
// max size: 100kB
|
||||
var buf: []u8 = try allocator.alloc(u8, 100 * 1024);
|
||||
const buf: []u8 = try allocator.alloc(u8, 100 * 1024);
|
||||
defer allocator.free(buf);
|
||||
var fba = std.heap.FixedBufferAllocator.init(buf);
|
||||
var string = std.ArrayList(u8).init(fba.allocator());
|
||||
|
@ -399,7 +399,7 @@ fn command_update_readme(allocator: std.mem.Allocator, tag: []const u8) !void {
|
|||
// we need to put the \n back in.
|
||||
// TODO: change this by using some "search" iterator that just
|
||||
// returns indices etc
|
||||
var output_line = try std.fmt.allocPrint(allocator, "{s}\n", .{line});
|
||||
const output_line = try std.fmt.allocPrint(allocator, "{s}\n", .{line});
|
||||
defer allocator.free(output_line);
|
||||
_ = try writer.write(output_line);
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ pub const usage_pkg =
|
|||
;
|
||||
|
||||
pub fn gitLatestTag(gpa: Allocator, pkg_dir: []const u8) ![]const u8 {
|
||||
const result = try std.ChildProcess.exec(.{
|
||||
const result = try std.ChildProcess.run(.{
|
||||
.allocator = gpa,
|
||||
.argv = &.{
|
||||
"git",
|
||||
|
@ -97,7 +97,7 @@ pub fn gitLatestTag(gpa: Allocator, pkg_dir: []const u8) ![]const u8 {
|
|||
}
|
||||
|
||||
pub fn gitFileList(gpa: Allocator, pkg_dir: []const u8) ![]const u8 {
|
||||
const result = try std.ChildProcess.exec(.{
|
||||
const result = try std.ChildProcess.run(.{
|
||||
.allocator = gpa,
|
||||
.argv = &.{
|
||||
"git",
|
||||
|
@ -266,8 +266,8 @@ pub fn cmdPkg(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
|
|||
|
||||
// computePackageHash will close the directory after completion
|
||||
// std.debug.print("abspath: {s}\n", .{cwd_absolute_path});
|
||||
var cwd_copy = try fs.openIterableDirAbsolute(cwd_absolute_path, .{});
|
||||
errdefer cwd_copy.dir.close();
|
||||
var cwd_copy = try fs.openDirAbsolute(cwd_absolute_path, .{ .iterate = true });
|
||||
errdefer cwd_copy.close();
|
||||
|
||||
var thread_pool: ThreadPool = undefined;
|
||||
try thread_pool.init(.{ .allocator = gpa });
|
||||
|
@ -281,7 +281,7 @@ pub fn cmdPkg(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
|
|||
};
|
||||
break :blk try computePackageHashExcludingDirectories(
|
||||
&thread_pool,
|
||||
.{ .dir = cwd_copy.dir },
|
||||
cwd_copy,
|
||||
excluded_directories,
|
||||
);
|
||||
};
|
||||
|
@ -355,7 +355,7 @@ fn isExecutable(file: fs.File) !bool {
|
|||
|
||||
pub fn computePackageHashExcludingDirectories(
|
||||
thread_pool: *ThreadPool,
|
||||
pkg_dir: fs.IterableDir,
|
||||
pkg_dir: fs.Dir,
|
||||
excluded_directories: []const []const u8,
|
||||
) ![Manifest.Hash.digest_length]u8 {
|
||||
const gpa = thread_pool.allocator;
|
||||
|
@ -405,7 +405,7 @@ pub fn computePackageHashExcludingDirectories(
|
|||
.failure = undefined, // to be populated by the worker
|
||||
};
|
||||
wait_group.start();
|
||||
try thread_pool.spawn(workerHashFile, .{ pkg_dir.dir, hashed_file, &wait_group });
|
||||
try thread_pool.spawn(workerHashFile, .{ pkg_dir, hashed_file, &wait_group });
|
||||
|
||||
try all_files.append(hashed_file);
|
||||
}
|
||||
|
|
|
@ -4,11 +4,9 @@ pub fn main() !void {
|
|||
var gpa = std.heap.GeneralPurposeAllocator(.{
|
||||
.thread_safe = true,
|
||||
}){};
|
||||
var allocator = gpa.allocator();
|
||||
const allocator = gpa.allocator();
|
||||
|
||||
var server = std.http.Server.init(allocator, .{
|
||||
.reuse_address = true,
|
||||
});
|
||||
var server = std.http.Server.init(.{ .reuse_address = true });
|
||||
defer server.deinit();
|
||||
|
||||
const address = try std.net.Address.parseIp("127.0.0.1", 3000);
|
||||
|
@ -30,7 +28,7 @@ pub fn main() !void {
|
|||
res.transfer_encoding = .{ .content_length = server_body.len };
|
||||
try res.headers.append("content-type", "text/plain");
|
||||
try res.headers.append("connection", "close");
|
||||
try res.do();
|
||||
try res.send(); // do() -> send()?
|
||||
|
||||
var buf: [128]u8 = undefined;
|
||||
_ = try res.readAll(&buf);
|
||||
|
|
Loading…
Add table
Reference in a new issue