Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion geoip.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package geoip

/*
#cgo pkg-config: geoip
#cgo pkg-config: geoip
#include <stdio.h>
#include <errno.h>
#include <GeoIP.h>
Expand Down Expand Up @@ -338,3 +338,19 @@ func (gi *GeoIP) GetCountry_v6(ip string) (cc string, netmask int) {
}
return
}

func (gi *GeoIP) GetDatabaseInfo() string {
if gi.db == nil {
return ""
}

gi.mu.Lock()
defer gi.mu.Unlock()

cdbinfo := C.GeoIP_database_info(gi.db)
defer C.free(unsafe.Pointer(cdbinfo))
if cdbinfo != nil {
return C.GoString(cdbinfo)
}
return ""
}
11 changes: 11 additions & 0 deletions geoip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,14 @@ func (s *GeoIPSuite) TestRegionName(c *C) {
regionName = GetRegionName("CA", "ON")
c.Check(regionName, Equals, "Ontario")
}

func (s *GeoIPSuite) TestDatabaseInfo(c *C) {
gi, err := Open("test-db/GeoIP.dat")
if err != nil {
fmt.Printf("Could not open GeoIP database: %s\n", err)
return
}

databaseInfo := gi.GetDatabaseInfo()
c.Check(databaseInfo, Equals, "")
}