Conversation
| const arena = try allocator.create(std.heap.ArenaAllocator); | ||
| arena.* = std.heap.ArenaAllocator.init(allocator); |
There was a problem hiding this comment.
Why not var arena = std.heap.ArenaAllocator.init(allocator);?
| } | ||
|
|
||
| var writer = try std.Io.Writer.Allocating.initCapacity( | ||
| self.arena.allocator(), |
There was a problem hiding this comment.
Is an arena really the right model here? I imagine you'll make a lot of http requests whose responses are fairly disposable, but whose memory footprint will grow the arena over time without freeing anything until very late in the program lifespan.
| ); | ||
| errdefer writer.deinit(); | ||
| const status = (try (self.client.fetch(.{ | ||
| .location = .{ .url = url }, |
There was a problem hiding this comment.
shouldn't you specify .method = POST here?
| .payload = body, | ||
| .headers = headers, | ||
| }) catch |err| switch (err) { | ||
| error.HttpConnectionClosing => { |
There was a problem hiding this comment.
personally I would be making a private inner version of get/post since these two functions are so similar
|
|
||
| fn overview( | ||
| arena: *std.heap.ArenaAllocator, | ||
| stats: anytype, |
There was a problem hiding this comment.
it's interesting, you seem to prefer anonymous structs much more than me. I would probably have a single Overview struct instead of accepting anytype. I generally think type-first which could be seen as a limitation in languages where I can't annotate as heavily as I may want.
| } else null; | ||
| defer if (excluded_langs) |excluded| allocator.free(excluded); | ||
|
|
||
| var stats: Statistics = undefined; |
There was a problem hiding this comment.
why use the = undefined pattern here but the labeled breaks above?
| ) ![]const u8 { | ||
| const a = arena.allocator(); | ||
| var out_data = template; | ||
| // Vulnerable to template injection. In practice, this should never happen. |
There was a problem hiding this comment.
Another idea is to just use std.fmt.print. So convert your templates to use {[lang_list]s} syntax and you can just do std.fmt.print and pass the stats struct directly
There was a problem hiding this comment.
I didn't know you could pass named arguments like that. That's very interesting and much better than what I'm doing...
| fn get_basic_info( | ||
| client: *HttpClient, | ||
| allocator: std.mem.Allocator, | ||
| ) !struct { []u32, []const u8, ?[]const u8 } { |
There was a problem hiding this comment.
personally it would bother me not having these named for the caller
| .ok => {}, | ||
| .accepted => { |
There was a problem hiding this comment.
this works out pretty nicely
| } | ||
| return; | ||
| } | ||
| } else { |
There was a problem hiding this comment.
so this would be hit when months = 1 and the limit is still exceeded? Interesting, I guess this works
Before merging, I will need to do some history revision to clean things up. One of the changes on this branch moves the generated files to their own branch, and I will need to manually fix some stuff up in accordance with that.