diff --git a/.forgejo/workflows/build.yaml b/.forgejo/workflows/build.yaml index 96afa3b..6109194 100644 --- a/.forgejo/workflows/build.yaml +++ b/.forgejo/workflows/build.yaml @@ -19,7 +19,7 @@ jobs: - name: Build project run: zig build --summary all - name: Run tests - run: zig build test --summary all + run: zig build test -Ddownload-geoip --summary all - name: Package run: zig build -Dtarget="$BUILD_TARGET" -Doptimize="$BUILD_OPTIMIZATION" - name: Upload diff --git a/src/config.zig b/src/config.zig index 197a7ca..b9602e0 100644 --- a/src/config.zig +++ b/src/config.zig @@ -5,8 +5,18 @@ pub const Config = struct { listen_port: u16, cache_size: usize, cache_dir: []const u8, + + /// GeoLite2 is used for GeoIP (IP -> geographic location) + /// IP2Location is a fallback if IP is not found in this db geolite_path: []const u8, + + /// Geocache file stores location lookups + /// (e.g. "Portland -> 45.52345°N, -122.67621° W). When not found in cache, + /// a web service from Nominatum (https://nominatim.org/) is used geocache_file: ?[]const u8, + + /// If provided, when GeoLite2 is missing data, https://www.ip2location.com/ + /// can be used. This will also be cached in the cached file ip2location_api_key: ?[]const u8, ip2location_cache_file: []const u8, diff --git a/src/location/GeoIp.zig b/src/location/GeoIp.zig index 9e78aa6..f037f9c 100644 --- a/src/location/GeoIp.zig +++ b/src/location/GeoIp.zig @@ -138,8 +138,12 @@ test "GeoIP init with invalid path fails" { } test "isUSIP detects US IPs" { + const allocator = std.testing.allocator; + const Config = @import("../config.zig").Config; + const config = try Config.load(allocator); + defer config.deinit(allocator); const build_options = @import("build_options"); - const db_path = "./GeoLite2-City.mmdb"; + const db_path = config.geolite_path; if (build_options.download_geoip) { const GeoLite2 = @import("GeoLite2.zig");