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:
parent
172ddd3e0f
commit
d258588454
1 changed files with 6 additions and 27 deletions
|
@ -96,11 +96,7 @@ fn postUser(e: *zap.SimpleEndpoint, r: zap.SimpleRequest) void {
|
||||||
_ = e;
|
_ = e;
|
||||||
if (r.body) |body| {
|
if (r.body) |body| {
|
||||||
var stream = std.json.TokenStream.init(body);
|
var stream = std.json.TokenStream.init(body);
|
||||||
var maybe_user: ?User = std.json.parse(
|
var maybe_user: ?User = std.json.parse(User, &stream, .{ .allocator = alloc }) catch null;
|
||||||
User,
|
|
||||||
&stream,
|
|
||||||
.{ .allocator = alloc },
|
|
||||||
) catch null;
|
|
||||||
if (maybe_user) |u| {
|
if (maybe_user) |u| {
|
||||||
defer std.json.parseFree(User, u, .{ .allocator = alloc });
|
defer std.json.parseFree(User, u, .{ .allocator = alloc });
|
||||||
if (users.addByName(u.first_name, u.last_name)) |id| {
|
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 (users.get(id)) |_| {
|
||||||
if (r.body) |body| {
|
if (r.body) |body| {
|
||||||
var stream = std.json.TokenStream.init(body);
|
var stream = std.json.TokenStream.init(body);
|
||||||
var maybe_user: ?User = std.json.parse(
|
var maybe_user: ?User = std.json.parse(User, &stream, .{ .allocator = alloc }) catch null;
|
||||||
User,
|
|
||||||
&stream,
|
|
||||||
.{ .allocator = alloc },
|
|
||||||
) catch null;
|
|
||||||
if (maybe_user) |u| {
|
if (maybe_user) |u| {
|
||||||
defer std.json.parseFree(
|
defer std.json.parseFree(User, u, .{ .allocator = alloc });
|
||||||
User,
|
|
||||||
u,
|
|
||||||
.{ .allocator = alloc },
|
|
||||||
);
|
|
||||||
var jsonbuf: [128]u8 = undefined;
|
var jsonbuf: [128]u8 = undefined;
|
||||||
if (users.update(id, u.first_name, u.last_name)) {
|
if (users.update(id, u.first_name, u.last_name)) {
|
||||||
if (zap.stringifyBuf(&jsonbuf, .{
|
if (zap.stringifyBuf(&jsonbuf, .{ .status = "OK", .id = id }, .{})) |json| {
|
||||||
.status = "OK",
|
|
||||||
.id = id,
|
|
||||||
}, .{})) |json| {
|
|
||||||
_ = r.sendJson(json);
|
_ = r.sendJson(json);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (zap.stringifyBuf(&jsonbuf, .{
|
if (zap.stringifyBuf(&jsonbuf, .{ .status = "ERROR", .id = id }, .{})) |json| {
|
||||||
.status = "ERROR",
|
|
||||||
.id = id,
|
|
||||||
}, .{})) |json| {
|
|
||||||
_ = r.sendJson(json);
|
_ = r.sendJson(json);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -166,10 +148,7 @@ fn deleteUser(e: *zap.SimpleEndpoint, r: zap.SimpleRequest) void {
|
||||||
_ = r.sendJson(json);
|
_ = r.sendJson(json);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (zap.stringifyBuf(&jsonbuf, .{
|
if (zap.stringifyBuf(&jsonbuf, .{ .status = "ERROR", .id = id }, .{})) |json| {
|
||||||
.status = "ERROR",
|
|
||||||
.id = id,
|
|
||||||
}, .{})) |json| {
|
|
||||||
_ = r.sendJson(json);
|
_ = r.sendJson(json);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue