From a2c2641558e772b6648bd634eefab7e1758f556c Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Thu, 18 Dec 2025 14:57:52 -0800 Subject: [PATCH] clean up .gitignore/main.zig --- .gitignore | 9 +-------- .mise.toml | 2 ++ .pre-commit-config.yaml | 30 ++++++++++++++++++++++++++++++ src/main.zig | 24 +++++++----------------- 4 files changed, 40 insertions(+), 25 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.gitignore b/.gitignore index 1561ae7..55c1422 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,4 @@ -ve/ -share/static/fonts/ -*.pyc -data/ -log/ -.idea/ *.swp -*.mmdb -*.dat +GeoLite2-City.mmdb .zig-cache/ zig-out/ diff --git a/.mise.toml b/.mise.toml index 99f262b..c03c643 100644 --- a/.mise.toml +++ b/.mise.toml @@ -1,3 +1,5 @@ [tools] +pre-commit = "4.2.0" +"ubi:DonIsaac/zlint" = "0.7.6" zig = "0.15.2" zls = "0.15.0" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..c335920 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,30 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + - repo: https://github.com/batmac/pre-commit-zig + rev: v0.3.0 + hooks: + - id: zig-fmt + - id: zig-build + - repo: local + hooks: + - id: test + name: Run zig build test + entry: zig + args: ["build", "--verbose", "test"] + language: system + types: [file] + pass_filenames: false + - id: zlint + name: Run zlint + entry: zlint + args: ["--deny-warnings", "--fix"] + language: system + types: [zig] diff --git a/src/main.zig b/src/main.zig index 7e35c2d..72017f0 100644 --- a/src/main.zig +++ b/src/main.zig @@ -11,40 +11,30 @@ const Airports = @import("location/Airports.zig"); const Resolver = @import("location/resolver.zig").Resolver; const GeoLite2 = @import("location/GeoLite2.zig"); -pub const std_options: std.Options = .{ - .log_level = .info, -}; - pub fn main() !void { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; defer _ = gpa.deinit(); const allocator = gpa.allocator(); - var stdout_buffer: [4096]u8 = undefined; - var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer); - const stdout = &stdout_writer.interface; - const cfg = try config.Config.load(allocator); defer cfg.deinit(allocator); - try stdout.print("wttr starting on {s}:{d}\n", .{ cfg.listen_host, cfg.listen_port }); - try stdout.print("Cache size: {d}\n", .{cfg.cache_size}); - try stdout.print("Cache dir: {s}\n", .{cfg.cache_dir}); - try stdout.print("GeoLite2 path: {s}\n", .{cfg.geolite_path}); + std.log.info("wttr starting on {s}:{d}\n", .{ cfg.listen_host, cfg.listen_port }); + std.log.info("Cache size: {d}\n", .{cfg.cache_size}); + std.log.info("Cache dir: {s}\n", .{cfg.cache_dir}); + std.log.info("GeoLite2 path: {s}\n", .{cfg.geolite_path}); if (cfg.geocache_file) |f| { - try stdout.print("Geocache file: {s}\n", .{f}); + std.log.info("Geocache file: {s}\n", .{f}); } else { - try stdout.print("Geocache: in-memory only\n", .{}); + std.log.info("Geocache: in-memory only\n", .{}); } - try stdout.flush(); // Ensure GeoLite2 database exists try GeoLite2.ensureDatabase(allocator, cfg.geolite_path); // Initialize GeoIP database var geoip = GeoIp.init(cfg.geolite_path) catch |err| { - std.log.warn("Failed to load GeoIP database: {}", .{err}); - std.log.warn("IP-based location resolution will be unavailable", .{}); + std.log.err("Failed to load GeoIP database from {s}: {}", .{ cfg.geolite_path, err }); return err; }; defer geoip.deinit();