look for database in default directory, download it during ci tests
This commit is contained in:
parent
cb3a51e47f
commit
06720cc53c
3 changed files with 16 additions and 2 deletions
|
|
@ -19,7 +19,7 @@ jobs:
|
||||||
- name: Build project
|
- name: Build project
|
||||||
run: zig build --summary all
|
run: zig build --summary all
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: zig build test --summary all
|
run: zig build test -Ddownload-geoip --summary all
|
||||||
- name: Package
|
- name: Package
|
||||||
run: zig build -Dtarget="$BUILD_TARGET" -Doptimize="$BUILD_OPTIMIZATION"
|
run: zig build -Dtarget="$BUILD_TARGET" -Doptimize="$BUILD_OPTIMIZATION"
|
||||||
- name: Upload
|
- name: Upload
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,18 @@ pub const Config = struct {
|
||||||
listen_port: u16,
|
listen_port: u16,
|
||||||
cache_size: usize,
|
cache_size: usize,
|
||||||
cache_dir: []const u8,
|
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,
|
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,
|
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_api_key: ?[]const u8,
|
||||||
ip2location_cache_file: []const u8,
|
ip2location_cache_file: []const u8,
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -138,8 +138,12 @@ test "GeoIP init with invalid path fails" {
|
||||||
}
|
}
|
||||||
|
|
||||||
test "isUSIP detects US IPs" {
|
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 build_options = @import("build_options");
|
||||||
const db_path = "./GeoLite2-City.mmdb";
|
const db_path = config.geolite_path;
|
||||||
|
|
||||||
if (build_options.download_geoip) {
|
if (build_options.download_geoip) {
|
||||||
const GeoLite2 = @import("GeoLite2.zig");
|
const GeoLite2 = @import("GeoLite2.zig");
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue