-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlookup.zig
More file actions
23 lines (18 loc) · 815 Bytes
/
lookup.zig
File metadata and controls
23 lines (18 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const std = @import("std");
const maxminddb = @import("maxminddb");
const db_path = "test-data/test-data/GeoIP2-City-Test.mmdb";
pub fn main() !void {
var gpa: std.heap.DebugAllocator(.{}) = .init;
const allocator = gpa.allocator();
defer _ = gpa.detectLeaks();
var db = try maxminddb.Reader.open(allocator, db_path, .{});
defer db.close();
// Note, for better performance use arena allocator and reset it after calling lookup().
// You won't need to call city.deinit() in that case.
const ip = try std.net.Address.parseIp("89.160.20.128", 0);
const city = try db.lookup(maxminddb.geoip2.City, allocator, ip, .{}) orelse return;
defer city.deinit();
for (city.value.country.names.?.entries) |e| {
std.debug.print("{s} = {s}\n", .{ e.key, e.value });
}
}