R
R
recloudor2016-08-02 16:41:27
go
recloudor, 2016-08-02 16:41:27

go. How to get the time zone by IP?

I rummaged through the geoip libraries, did not find what I needed.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maksim Kochkin, 2016-08-19
@recloudor

https://github.com/oschwald/geoip2-golang - reads MaxMind databases ( GeoLite2 , GeoIP2 )
(ahtung, error handling is omitted in the example)

db, err := geoip2.Open("GeoIP2-City.mmdb")
    ip := net.ParseIP("81.2.69.142")
    record, err := db.City(ip)
    fmt.Printf("Russian country name: %v\n", record.Country.Names["ru"])
    fmt.Printf("Time zone: %v\n", record.Location.TimeZone)

    // Output:
    // Russian country name: Великобритания
    // Time zone: Europe/London

www.devdungeon.com/content/ip-geolocation-go - a post about using third-party APIs for this purpose.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question