move metno initialization earlier so less work is done if the environment variable is not set

This commit is contained in:
Emil Lerch 2026-01-05 13:43:33 -08:00
parent b2cb5d537f
commit 87ffe7d598
Signed by: lobo
GPG key ID: A7B62D657EF764F8

View file

@ -9,6 +9,7 @@ const GeoCache = @import("location/GeoCache.zig");
const Airports = @import("location/Airports.zig"); const Airports = @import("location/Airports.zig");
const Resolver = @import("location/resolver.zig").Resolver; const Resolver = @import("location/resolver.zig").Resolver;
const GeoLite2 = @import("location/GeoLite2.zig"); const GeoLite2 = @import("location/GeoLite2.zig");
const version = @import("build_options").version;
pub fn main() !u8 { pub fn main() !u8 {
var gpa = std.heap.GeneralPurposeAllocator(.{}){}; var gpa = std.heap.GeneralPurposeAllocator(.{}){};
@ -18,7 +19,7 @@ pub fn main() !u8 {
const cfg = try Config.load(allocator); const cfg = try Config.load(allocator);
defer cfg.deinit(allocator); defer cfg.deinit(allocator);
std.log.info("wttr starting on {s}:{d}", .{ cfg.listen_host, cfg.listen_port }); std.log.info("wttr version {s} starting on {s}:{d}", .{ version, cfg.listen_host, cfg.listen_port });
std.log.info("Cache size: {d}", .{cfg.cache_size}); std.log.info("Cache size: {d}", .{cfg.cache_size});
std.log.info("Cache dir: {s}", .{cfg.cache_dir}); std.log.info("Cache dir: {s}", .{cfg.cache_dir});
std.log.info("GeoLite2 path: {s}", .{cfg.geolite_path}); std.log.info("GeoLite2 path: {s}", .{cfg.geolite_path});
@ -28,6 +29,12 @@ pub fn main() !u8 {
std.log.info("Geocache: in-memory only", .{}); std.log.info("Geocache: in-memory only", .{});
} }
var metno = MetNo.init(allocator, null) catch |err| {
if (err == MetNo.MissingIdentificationError) return 1;
return err;
};
defer metno.deinit();
// Ensure GeoLite2 database exists // Ensure GeoLite2 database exists
try GeoLite2.ensureDatabase(allocator, cfg.geolite_path); try GeoLite2.ensureDatabase(allocator, cfg.geolite_path);
@ -67,12 +74,6 @@ pub fn main() !u8 {
}); });
defer rate_limiter.deinit(); defer rate_limiter.deinit();
var metno = MetNo.init(allocator, null) catch |err| {
if (err == MetNo.MissingIdentificationError) return 1;
return err;
};
defer metno.deinit();
var server = try Server.init(allocator, cfg.listen_host, cfg.listen_port, .{ var server = try Server.init(allocator, cfg.listen_host, cfg.listen_port, .{
.provider = metno.provider(cache), .provider = metno.provider(cache),
.resolver = &resolver, .resolver = &resolver,