Open embedded file using geoip2 library. Is it possible?
hadan opened this issue · comments
Hi, I am newbie in go and try to use pkger to embed a file that will be open by other library (github.com/oschwald/geoip2-golang) instead of standard package os. So far, no success.
Here's the snippet
func main() {
pkger.Include("/GeoLite2-Country.mmdb")
// _, err := pkger.Open("/GeoLite2-Country.mmdb")
// if err != nil {
// log.Fatal(err)
// }
// db, err := geoip2.Open("GeoLite2-Country.mmdb") //this works .mmdb outside compiled file/binary
// doesn't work
db, err := geoip2.Open("/GeoLite2-Country.mmdb")
if err != nil {
log.Fatal(err)
}
ip := net.ParseIP("202.14.44.123")
record, err := db.Country(ip)
if err != nil {
log.Fatal(err)
}
fmt.Printf("The country: %s",record.Country.Names["en"])
defer db.Close()
}
Am I missing something?
Thank you
@hadan Try to use pkger.Open
, ioutil.ReadAll
and geoip2.FromBytes
.