You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
366 B
19 lines
366 B
package tools
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/oschwald/geoip2-golang"
|
|
"net"
|
|
)
|
|
|
|
func GetCity(path, ipAddress string) (string, string) {
|
|
db, err := geoip2.Open(path)
|
|
if err != nil {
|
|
return "", ""
|
|
}
|
|
defer db.Close()
|
|
record, err := db.City(net.ParseIP(ipAddress))
|
|
fmt.Println(record.City.Names["en"])
|
|
return record.Country.Names["en"], record.City.Names["en"]
|
|
}
|