Ejemplo n.º 1
0
// Open the GeoIP database
func (g *GeoIP) openDatabase(file string) (*geoip.GeoIP, error) {
	dbpath := GetConfig().GeoipDatabasePath
	if len(dbpath) > 0 {
		dbpath += "/"
	}

	filename := dbpath + file

	if _, err := os.Stat(filename + geoipUpdatedExt); !os.IsNotExist(err) {
		filename += geoipUpdatedExt
	}

	return geoip.Open(filename)
}
Ejemplo n.º 2
0
// Open the GeoIP database
func (g *GeoIP) openDatabase(file string) (*geoip.GeoIP, time.Time, error) {
	dbpath := GetConfig().GeoipDatabasePath
	if dbpath != "" && !strings.HasSuffix(dbpath, "/") {
		dbpath += "/"
	}

	filename := dbpath + file

	var err error
	var fi os.FileInfo
	var modTime time.Time

	if fi, err = os.Stat(filename + geoipUpdatedExt); !os.IsNotExist(err) {
		filename += geoipUpdatedExt
	}

	if fi != nil {
		modTime = fi.ModTime()
	}

	db, err := geoip.Open(filename)
	return db, modTime, err
}