now that we have a cache directory, default geocache file to that directory
This commit is contained in:
parent
0edd212db0
commit
cb3a51e47f
1 changed files with 3 additions and 4 deletions
|
|
@ -17,10 +17,10 @@ pub const Config = struct {
|
|||
// Get XDG_CACHE_HOME or default to ~/.cache
|
||||
const home = env.get("HOME") orelse "/tmp";
|
||||
const xdg_cache = env.get("XDG_CACHE_HOME") orelse
|
||||
try std.fmt.allocPrint(allocator, "{s}/.cache", .{home});
|
||||
try std.fs.path.join(allocator, &[_][]const u8{ home, ".cache" });
|
||||
defer if (env.get("XDG_CACHE_HOME") == null) allocator.free(xdg_cache);
|
||||
|
||||
const default_cache_dir = try std.fmt.allocPrint(allocator, "{s}/wttr", .{xdg_cache});
|
||||
const default_cache_dir = try std.fs.path.join(allocator, &[_][]const u8{ xdg_cache, "wttr" });
|
||||
defer allocator.free(default_cache_dir);
|
||||
|
||||
return Config{
|
||||
|
|
@ -42,7 +42,7 @@ pub const Config = struct {
|
|||
env.get("WTTR_CACHE_DIR") orelse default_cache_dir,
|
||||
});
|
||||
},
|
||||
.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 try std.fs.path.join(allocator, &[_][]const u8{ default_cache_dir, "geocache.json" }),
|
||||
.ip2location_api_key = if (env.get("IP2LOCATION_API_KEY")) |v| try allocator.dupe(u8, v) else null,
|
||||
.ip2location_cache_file = blk: {
|
||||
if (env.get("IP2LOCATION_CACHE_FILE")) |v| {
|
||||
|
|
@ -71,5 +71,4 @@ test "config loads defaults" {
|
|||
try std.testing.expectEqualStrings("0.0.0.0", cfg.listen_host);
|
||||
try std.testing.expectEqual(@as(u16, 8002), cfg.listen_port);
|
||||
try std.testing.expectEqual(@as(usize, 10_000), cfg.cache_size);
|
||||
try std.testing.expect(cfg.geocache_file == null);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue