make config more readable

This commit is contained in:
Emil Lerch 2025-12-18 14:46:08 -08:00
parent 5614225050
commit e0decf9df9
Signed by: lobo
GPG key ID: A7B62D657EF764F8

View file

@ -13,16 +13,16 @@ pub const Config = struct {
defer env.deinit(); defer env.deinit();
return Config{ return Config{
.listen_host = env.get("WTTR_LISTEN_HOST") orelse try allocator.dupe(u8, "0.0.0.0"), .listen_host = env.get("WTTR_LISTEN_HOST") orelse try allocator.dupe(u8, "0.0.0.0"),
.listen_port = blk: { .listen_port = if (env.get("WTTR_LISTEN_PORT")) |p|
const port_str = env.get("WTTR_LISTEN_PORT") orelse break :blk 8002; try std.fmt.parseInt(u16, p, 10)
break :blk std.fmt.parseInt(u16, port_str, 10) catch 8002; else
}, 8002,
.cache_size = blk: { .cache_size = if (env.get("WTTR_CACHE_SIZE")) |s|
const size_str = env.get("WTTR_CACHE_SIZE") orelse break :blk 10_000; try std.fmt.parseInt(usize, s, 10)
break :blk std.fmt.parseInt(usize, size_str, 10) catch 10_000; else
}, 10_000,
.cache_dir = if (env.get("WTTR_CACHE_DIR")) |v| try allocator.dupe(u8, v) else try allocator.dupe(u8, "/tmp/wttr-cache"), .cache_dir = try allocator.dupe(u8, env.get("WTTR_CACHE_DIR") orelse "/tmp/wttr-cache"),
.geolite_path = if (env.get("WTTR_GEOLITE_PATH")) |v| try allocator.dupe(u8, v) else try allocator.dupe(u8, "./GeoLite2-City.mmdb"), .geolite_path = try allocator.dupe(u8, env.get("WTTR_GEOLITE_PATH") orelse "./GeoLite2-City.mmdb"),
.geocache_file = if (env.get("WTTR_GEOCACHE_FILE")) |v| try allocator.dupe(u8, v) else null, .geocache_file = if (env.get("WTTR_GEOCACHE_FILE")) |v| try allocator.dupe(u8, v) else null,
}; };
} }