diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-05-20 10:16:50 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-05-20 10:16:50 +0200 |
| commit | 44445734ba4a0f05564f808c2fd34a7f23c6fafb (patch) | |
| tree | 3bd22add718620cbf931286f55137bcc666100be /src/config.zig | |
| parent | 95ae9f15e1db335a7f8358d811ea37e2c89dd10f (diff) | |
Let's do a rewrite!
Created project structure and changed `build.zig` and added licence.
Diffstat (limited to 'src/config.zig')
| -rw-r--r-- | src/config.zig | 41 |
1 files changed, 0 insertions, 41 deletions
diff --git a/src/config.zig b/src/config.zig deleted file mode 100644 index 02d3c8a..0000000 --- a/src/config.zig +++ /dev/null @@ -1,41 +0,0 @@ -const std = @import("std"); - -const Self = @This(); - -const Config = struct { - storage_path: []const u8, - session_expires_after: usize, -}; - -arena: *std.heap.ArenaAllocator, -storage_path: []const u8, -session_expires_after: usize, - -pub fn load(allocator: std.mem.Allocator) !Self { - const home_path = std.posix.getenv("HOME") orelse return error.MissingHome; - const home = try std.fs.cwd().openDirZ( - home_path, - .{}, - ); - const file = home.openFile( - ".config/memora/config.json", - .{} - ) catch return error.MissingConfig; - - const content = try file.readToEndAlloc(allocator, std.math.maxInt(usize)); - defer allocator.free(content); - - const parsed = try std.json.parseFromSlice(Config, allocator, content, .{ - .allocate = .alloc_always, - }); - return .{ - .arena = parsed.arena, - .storage_path = parsed.value.storage_path, - .session_expires_after = parsed.value.session_expires_after * std.time.ns_per_day, - }; -} - -pub fn deinit(self: *Self) void { - self.arena.deinit(); - self.* = undefined; -} |