better naming

This commit is contained in:
Emil Lerch 2026-01-06 17:12:38 -08:00
parent 58f6e390bd
commit 4ec74d8967
Signed by: lobo
GPG key ID: A7B62D657EF764F8
8 changed files with 18 additions and 17 deletions

View file

@ -3,11 +3,11 @@ const httpz = @import("httpz");
const WeatherProvider = @import("../weather/Provider.zig");
const Resolver = @import("../location/resolver.zig").Resolver;
const QueryParams = @import("query.zig").QueryParams;
const formatted = @import("../render/formatted.zig");
const line = @import("../render/line.zig");
const json = @import("../render/json.zig");
const v2 = @import("../render/v2.zig");
const custom = @import("../render/custom.zig");
const Formatted = @import("../render/Formatted.zig");
const Line = @import("../render/Line.zig");
const Json = @import("../render/Json.zig");
const V2 = @import("../render/V2.zig");
const Custom = @import("../render/Custom.zig");
const help = @import("help.zig");
const log = std.log.scoped(.handler);
@ -179,14 +179,14 @@ fn handleWeatherInternal(
res.content_type = .TEXT;
if (std.mem.eql(u8, fmt, "j1")) {
res.content_type = .JSON; // reset to json
break :blk try json.render(req_alloc, weather);
break :blk try Json.render(req_alloc, weather);
}
if (std.mem.eql(u8, fmt, "v2"))
break :blk try v2.render(req_alloc, weather, render_options.use_imperial);
break :blk try V2.render(req_alloc, weather, render_options.use_imperial);
if (std.mem.startsWith(u8, fmt, "%"))
break :blk try custom.render(req_alloc, weather, fmt, render_options.use_imperial);
break :blk try Custom.render(req_alloc, weather, fmt, render_options.use_imperial);
// fall back to line if we don't understand the format parameter
break :blk try line.render(req_alloc, weather, fmt, render_options.use_imperial);
break :blk try Line.render(req_alloc, weather, fmt, render_options.use_imperial);
} else {
render_options.format = determineFormat(params, req.headers.get("user-agent"));
log.debug(
@ -194,12 +194,12 @@ fn handleWeatherInternal(
.{ render_options.format, params.ansi, params.text_only, req.headers.get("user-agent") },
);
if (render_options.format != .html) res.content_type = .TEXT else res.content_type = .HTML;
break :blk try formatted.render(req_alloc, weather, render_options);
break :blk try Formatted.render(req_alloc, weather, render_options);
}
};
}
fn determineFormat(params: QueryParams, user_agent: ?[]const u8) formatted.Format {
fn determineFormat(params: QueryParams, user_agent: ?[]const u8) Formatted.Format {
if (params.ansi or params.text_only) {
// user explicitly requested something. If both are set, text will win
if (params.text_only) return .plain_text;

View file

@ -1,5 +1,5 @@
const std = @import("std");
const RenderOptions = @import("../render/formatted.zig").RenderOptions;
const RenderOptions = @import("../render/Formatted.zig").RenderOptions;
///Units:
///

View file

@ -92,10 +92,11 @@ test {
_ = @import("http/RateLimiter.zig");
_ = @import("http/query.zig");
_ = @import("http/help.zig");
_ = @import("render/line.zig");
_ = @import("render/json.zig");
_ = @import("render/v2.zig");
_ = @import("render/custom.zig");
_ = @import("render/Formatted.zig");
_ = @import("render/Line.zig");
_ = @import("render/Json.zig");
_ = @import("render/V2.zig");
_ = @import("render/Custom.zig");
_ = @import("location/GeoIp.zig");
_ = @import("location/GeoCache.zig");
_ = @import("location/Airports.zig");

View file

@ -923,7 +923,7 @@ test "unknown weather code art" {
}
test "temperature matches between ansi and custom format" {
const custom = @import("custom.zig");
const custom = @import("Custom.zig");
const data = types.WeatherData{
.location = "PDX",