fix query args (http_query is a decl, not a field)
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Emil Lerch 2021-09-01 08:58:25 -07:00
parent 3005e07cee
commit 535205e947
Signed by: lobo
GPG Key ID: A7B62D657EF764F8

View File

@ -410,7 +410,7 @@ fn buildQuery(allocator: *std.mem.Allocator, request: anytype) ![]const u8 {
defer buffer.deinit(); defer buffer.deinit();
var has_begun = false; var has_begun = false;
const Req = @TypeOf(request); const Req = @TypeOf(request);
if (std.meta.fieldIndex(Req, "http_query") == null) if (declaration(Req, "http_query") == null)
return buffer.toOwnedSlice(); return buffer.toOwnedSlice();
const query_arguments = Req.http_query; const query_arguments = Req.http_query;
inline for (@typeInfo(@TypeOf(query_arguments)).Struct.fields) |arg| { inline for (@typeInfo(@TypeOf(query_arguments)).Struct.fields) |arg| {
@ -428,6 +428,14 @@ fn buildQuery(allocator: *std.mem.Allocator, request: anytype) ![]const u8 {
return buffer.toOwnedSlice(); return buffer.toOwnedSlice();
} }
fn declaration(comptime T: type, name: []const u8) ?std.builtin.TypeInfo.Declaration {
for (std.meta.declarations(T)) |decl| {
if (std.mem.eql(u8, name, decl.name))
return decl;
}
return null;
}
fn addQueryArg(key: []const u8, value: anytype, writer: anytype, start: bool) !void { fn addQueryArg(key: []const u8, value: anytype, writer: anytype, start: bool) !void {
if (start) if (start)
_ = try writer.write("?") _ = try writer.write("?")