clean up .gitignore/main.zig
This commit is contained in:
parent
e0decf9df9
commit
a2c2641558
4 changed files with 40 additions and 25 deletions
9
.gitignore
vendored
9
.gitignore
vendored
|
|
@ -1,11 +1,4 @@
|
|||
ve/
|
||||
share/static/fonts/
|
||||
*.pyc
|
||||
data/
|
||||
log/
|
||||
.idea/
|
||||
*.swp
|
||||
*.mmdb
|
||||
*.dat
|
||||
GeoLite2-City.mmdb
|
||||
.zig-cache/
|
||||
zig-out/
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
[tools]
|
||||
pre-commit = "4.2.0"
|
||||
"ubi:DonIsaac/zlint" = "0.7.6"
|
||||
zig = "0.15.2"
|
||||
zls = "0.15.0"
|
||||
|
|
|
|||
30
.pre-commit-config.yaml
Normal file
30
.pre-commit-config.yaml
Normal file
|
|
@ -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]
|
||||
24
src/main.zig
24
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();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue