// openDB opens and returns the IP database file or URL. func openDB(c *Config) (*freegeoip.DB, error) { u, err := url.Parse(c.DB) if err != nil || len(u.Scheme) == 0 { return freegeoip.Open(c.DB) } return freegeoip.OpenURL(c.DB, c.UpdateInterval, c.RetryInterval) }
// openDB opens and returns the IP database. func openDB(dsn string, updateIntvl, maxRetryIntvl time.Duration) (db *freegeoip.DB, err error) { u, err := url.Parse(dsn) if err != nil || len(u.Scheme) == 0 { db, err = freegeoip.Open(dsn) } else { db, err = freegeoip.OpenURL(dsn, updateIntvl, maxRetryIntvl) } return }
// openDB opens and returns the IP database file or URL. func openDB(c *Config) (*freegeoip.DB, error) { // This is a paid product. Get the updates URL. if len(c.UserID) > 0 && len(c.LicenseKey) > 0 { var err error c.DB, err = freegeoip.GeoIPUpdateURL(c.UpdatesHost, c.UserID, c.LicenseKey, c.ProductID) if err != nil { return nil, err } else { log.Println("Using updates URL:", c.DB) } } u, err := url.Parse(c.DB) if err != nil || len(u.Scheme) == 0 { return freegeoip.Open(c.DB) } return freegeoip.OpenURL(c.DB, c.UpdateInterval, c.RetryInterval) }
func lookupIP(ip string) (float64, float64) { updateInterval := 7 * 24 * time.Hour // week maxRetryInterval := time.Hour db, err := freegeoip.OpenURL(maxmindFile, updateInterval, maxRetryInterval) if err != nil { log.Fatal(err) } defer db.Close() select { case <-db.NotifyOpen(): log.Println("Reading from the geoip file") case err := <-db.NotifyError(): log.Fatal(err) } var result customQuery err = db.Lookup(net.ParseIP(ip), &result) if err != nil { log.Fatal(err) } log.Printf("Approximate location is %v, %v\n", result.Location.Latitude, result.Location.Longitude) return result.Location.Latitude, result.Location.Longitude }