const std = @import("std"); pub const Config = struct { listen_host: []const u8, listen_port: u16, cache_size: usize, cache_dir: []const u8, geolite_path: []const u8, geolocator_url: []const u8, pub fn load(allocator: std.mem.Allocator) !Config { return Config{ .listen_host = std.process.getEnvVarOwned(allocator, "WTTR_LISTEN_HOST") catch try allocator.dupe(u8, "0.0.0.0"), .listen_port = blk: { const port_str = std.process.getEnvVarOwned(allocator, "WTTR_LISTEN_PORT") catch break :blk 8002; defer allocator.free(port_str); break :blk std.fmt.parseInt(u16, port_str, 10) catch 8002; }, .cache_size = blk: { const size_str = std.process.getEnvVarOwned(allocator, "WTTR_CACHE_SIZE") catch break :blk 10_000; defer allocator.free(size_str); break :blk std.fmt.parseInt(usize, size_str, 10) catch 10_000; }, .cache_dir = std.process.getEnvVarOwned(allocator, "WTTR_CACHE_DIR") catch try allocator.dupe(u8, "/tmp/wttr-cache"), .geolite_path = std.process.getEnvVarOwned(allocator, "WTTR_GEOLITE_PATH") catch try allocator.dupe(u8, "./GeoLite2-City.mmdb"), .geolocator_url = std.process.getEnvVarOwned(allocator, "WTTR_GEOLOCATOR_URL") catch try allocator.dupe(u8, "http://localhost:8004"), }; } pub fn deinit(self: Config, allocator: std.mem.Allocator) void { allocator.free(self.listen_host); allocator.free(self.cache_dir); allocator.free(self.geolite_path); allocator.free(self.geolocator_url); } };