1
0
Fork 0
mirror of https://github.com/zigzap/zap.git synced 2025-10-20 15:14:08 +00:00

cosmetics: longer line in endpoint example

This commit is contained in:
Rene Schallner 2023-01-19 21:28:07 +01:00
parent 172ddd3e0f
commit d258588454

View file

@ -96,11 +96,7 @@ fn postUser(e: *zap.SimpleEndpoint, r: zap.SimpleRequest) void {
_ = e;
if (r.body) |body| {
var stream = std.json.TokenStream.init(body);
var maybe_user: ?User = std.json.parse(
User,
&stream,
.{ .allocator = alloc },
) catch null;
var maybe_user: ?User = std.json.parse(User, &stream, .{ .allocator = alloc }) catch null;
if (maybe_user) |u| {
defer std.json.parseFree(User, u, .{ .allocator = alloc });
if (users.addByName(u.first_name, u.last_name)) |id| {
@ -122,30 +118,16 @@ fn putUser(e: *zap.SimpleEndpoint, r: zap.SimpleRequest) void {
if (users.get(id)) |_| {
if (r.body) |body| {
var stream = std.json.TokenStream.init(body);
var maybe_user: ?User = std.json.parse(
User,
&stream,
.{ .allocator = alloc },
) catch null;
var maybe_user: ?User = std.json.parse(User, &stream, .{ .allocator = alloc }) catch null;
if (maybe_user) |u| {
defer std.json.parseFree(
User,
u,
.{ .allocator = alloc },
);
defer std.json.parseFree(User, u, .{ .allocator = alloc });
var jsonbuf: [128]u8 = undefined;
if (users.update(id, u.first_name, u.last_name)) {
if (zap.stringifyBuf(&jsonbuf, .{
.status = "OK",
.id = id,
}, .{})) |json| {
if (zap.stringifyBuf(&jsonbuf, .{ .status = "OK", .id = id }, .{})) |json| {
_ = r.sendJson(json);
}
} else {
if (zap.stringifyBuf(&jsonbuf, .{
.status = "ERROR",
.id = id,
}, .{})) |json| {
if (zap.stringifyBuf(&jsonbuf, .{ .status = "ERROR", .id = id }, .{})) |json| {
_ = r.sendJson(json);
}
}
@ -166,10 +148,7 @@ fn deleteUser(e: *zap.SimpleEndpoint, r: zap.SimpleRequest) void {
_ = r.sendJson(json);
}
} else {
if (zap.stringifyBuf(&jsonbuf, .{
.status = "ERROR",
.id = id,
}, .{})) |json| {
if (zap.stringifyBuf(&jsonbuf, .{ .status = "ERROR", .id = id }, .{})) |json| {
_ = r.sendJson(json);
}
}