how can i use it with a pool like mysql
fancyecommerce opened this issue · 1 comments
fancyecommerce commented
func getIpInfo(ipStr string) (string, string, string, string){
ipDb, err := geoip2.Open("/www/test/ip/GeoLite2-City_20180327/GeoLite2-City.mmdb")
if err != nil {
log.Fatal(err)
}
defer ipDb.Close()
// If you are using strings that may be invalid, check that ip is not nil
ip := net.ParseIP(ipStr)
record, err := ipDb.City(ip)
if err != nil {
log.Fatal(err)
}
return record.Country.IsoCode, record.Country.Names["en"], record.Subdivisions[0].Names["en"], record.City.Names["en-US"]
}
every time use it , it will reopen db connect, them close connect, how can i use it with a pool ip db?
oschwald commented
You can just share the geoip.Reader
. There is no reason to open and close it each time.