better naming
This commit is contained in:
parent
58f6e390bd
commit
4ec74d8967
8 changed files with 18 additions and 17 deletions
|
|
@ -3,11 +3,11 @@ const httpz = @import("httpz");
|
||||||
const WeatherProvider = @import("../weather/Provider.zig");
|
const WeatherProvider = @import("../weather/Provider.zig");
|
||||||
const Resolver = @import("../location/resolver.zig").Resolver;
|
const Resolver = @import("../location/resolver.zig").Resolver;
|
||||||
const QueryParams = @import("query.zig").QueryParams;
|
const QueryParams = @import("query.zig").QueryParams;
|
||||||
const formatted = @import("../render/formatted.zig");
|
const Formatted = @import("../render/Formatted.zig");
|
||||||
const line = @import("../render/line.zig");
|
const Line = @import("../render/Line.zig");
|
||||||
const json = @import("../render/json.zig");
|
const Json = @import("../render/Json.zig");
|
||||||
const v2 = @import("../render/v2.zig");
|
const V2 = @import("../render/V2.zig");
|
||||||
const custom = @import("../render/custom.zig");
|
const Custom = @import("../render/Custom.zig");
|
||||||
const help = @import("help.zig");
|
const help = @import("help.zig");
|
||||||
|
|
||||||
const log = std.log.scoped(.handler);
|
const log = std.log.scoped(.handler);
|
||||||
|
|
@ -179,14 +179,14 @@ fn handleWeatherInternal(
|
||||||
res.content_type = .TEXT;
|
res.content_type = .TEXT;
|
||||||
if (std.mem.eql(u8, fmt, "j1")) {
|
if (std.mem.eql(u8, fmt, "j1")) {
|
||||||
res.content_type = .JSON; // reset to json
|
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"))
|
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, "%"))
|
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
|
// 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 {
|
} else {
|
||||||
render_options.format = determineFormat(params, req.headers.get("user-agent"));
|
render_options.format = determineFormat(params, req.headers.get("user-agent"));
|
||||||
log.debug(
|
log.debug(
|
||||||
|
|
@ -194,12 +194,12 @@ fn handleWeatherInternal(
|
||||||
.{ render_options.format, params.ansi, params.text_only, req.headers.get("user-agent") },
|
.{ 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;
|
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) {
|
if (params.ansi or params.text_only) {
|
||||||
// user explicitly requested something. If both are set, text will win
|
// user explicitly requested something. If both are set, text will win
|
||||||
if (params.text_only) return .plain_text;
|
if (params.text_only) return .plain_text;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const RenderOptions = @import("../render/formatted.zig").RenderOptions;
|
const RenderOptions = @import("../render/Formatted.zig").RenderOptions;
|
||||||
|
|
||||||
///Units:
|
///Units:
|
||||||
///
|
///
|
||||||
|
|
|
||||||
|
|
@ -92,10 +92,11 @@ test {
|
||||||
_ = @import("http/RateLimiter.zig");
|
_ = @import("http/RateLimiter.zig");
|
||||||
_ = @import("http/query.zig");
|
_ = @import("http/query.zig");
|
||||||
_ = @import("http/help.zig");
|
_ = @import("http/help.zig");
|
||||||
_ = @import("render/line.zig");
|
_ = @import("render/Formatted.zig");
|
||||||
_ = @import("render/json.zig");
|
_ = @import("render/Line.zig");
|
||||||
_ = @import("render/v2.zig");
|
_ = @import("render/Json.zig");
|
||||||
_ = @import("render/custom.zig");
|
_ = @import("render/V2.zig");
|
||||||
|
_ = @import("render/Custom.zig");
|
||||||
_ = @import("location/GeoIp.zig");
|
_ = @import("location/GeoIp.zig");
|
||||||
_ = @import("location/GeoCache.zig");
|
_ = @import("location/GeoCache.zig");
|
||||||
_ = @import("location/Airports.zig");
|
_ = @import("location/Airports.zig");
|
||||||
|
|
|
||||||
|
|
@ -923,7 +923,7 @@ test "unknown weather code art" {
|
||||||
}
|
}
|
||||||
|
|
||||||
test "temperature matches between ansi and custom format" {
|
test "temperature matches between ansi and custom format" {
|
||||||
const custom = @import("custom.zig");
|
const custom = @import("Custom.zig");
|
||||||
|
|
||||||
const data = types.WeatherData{
|
const data = types.WeatherData{
|
||||||
.location = "PDX",
|
.location = "PDX",
|
||||||
Loading…
Add table
Reference in a new issue