ip2location.go
func Open(dbpath string) {
	max_ipv6_range.SetString("340282366920938463463374607431768211455", 10)
	
	var err error
	f, err = os.Open(dbpath)
	if err != nil {
		return
	}
	
	meta.databasetype = readuint8(1)
	meta.databasecolumn = readuint8(2)
	meta.databaseyear = readuint8(3)
	meta.databasemonth = readuint8(4)
	meta.databaseday = readuint8(5)
	meta.ipv4databasecount = readuint32(6)
	meta.ipv4databaseaddr = readuint32(10)
	meta.ipv6databasecount = readuint32(14)
	meta.ipv6databaseaddr = readuint32(18)
	meta.ipv4indexbaseaddr = readuint32(22)
	meta.ipv6indexbaseaddr = readuint32(26)
	meta.ipv4columnsize = uint32(meta.databasecolumn << 2) // 4 bytes each column
	meta.ipv6columnsize = uint32(16 + ((meta.databasecolumn - 1) << 2)) // 4 bytes each column, except IPFrom column which is 16 bytes
	
	dbt := meta.databasetype
	
	// since both IPv4 and IPv6 use 4 bytes for the below columns, can just do it once here
	if country_position[dbt] != 0 {
		country_position_offset = uint32(country_position[dbt] - 1) << 2
		country_enabled = true
	}
	if region_position[dbt] != 0 {
		region_position_offset = uint32(region_position[dbt] - 1) << 2
		region_enabled = true
	}
	if city_position[dbt] != 0 {
		city_position_offset = uint32(city_position[dbt] - 1) << 2
		city_enabled = true
	}
	if isp_position[dbt] != 0 {
		isp_position_offset = uint32(isp_position[dbt] - 1) << 2
		isp_enabled = true
	}
	if domain_position[dbt] != 0 {
		domain_position_offset = uint32(domain_position[dbt] - 1) << 2
		domain_enabled = true
	}
	if zipcode_position[dbt] != 0 {
		zipcode_position_offset = uint32(zipcode_position[dbt] - 1) << 2
		zipcode_enabled = true
	}
	if latitude_position[dbt] != 0 {
		latitude_position_offset = uint32(latitude_position[dbt] - 1) << 2
		latitude_enabled = true
	}
	if longitude_position[dbt] != 0 {
		longitude_position_offset = uint32(longitude_position[dbt] - 1) << 2
		longitude_enabled = true
	}
	if timezone_position[dbt] != 0 {
		timezone_position_offset = uint32(timezone_position[dbt] - 1) << 2
		timezone_enabled = true
	}
	if netspeed_position[dbt] != 0 {
		netspeed_position_offset = uint32(netspeed_position[dbt] - 1) << 2
		netspeed_enabled = true
	}
	if iddcode_position[dbt] != 0 {
		iddcode_position_offset = uint32(iddcode_position[dbt] - 1) << 2
		iddcode_enabled = true
	}
	if areacode_position[dbt] != 0 {
		areacode_position_offset = uint32(areacode_position[dbt] - 1) << 2
		areacode_enabled = true
	}
	if weatherstationcode_position[dbt] != 0 {
		weatherstationcode_position_offset = uint32(weatherstationcode_position[dbt] - 1) << 2
		weatherstationcode_enabled = true
	}
	if weatherstationname_position[dbt] != 0 {
		weatherstationname_position_offset = uint32(weatherstationname_position[dbt] - 1) << 2
		weatherstationname_enabled = true
	}
	if mcc_position[dbt] != 0 {
		mcc_position_offset = uint32(mcc_position[dbt] - 1) << 2
		mcc_enabled = true
	}
	if mnc_position[dbt] != 0 {
		mnc_position_offset = uint32(mnc_position[dbt] - 1) << 2
		mnc_enabled = true
	}
	if mobilebrand_position[dbt] != 0 {
		mobilebrand_position_offset = uint32(mobilebrand_position[dbt] - 1) << 2
		mobilebrand_enabled = true
	}
	if elevation_position[dbt] != 0 {
		elevation_position_offset = uint32(elevation_position[dbt] - 1) << 2
		elevation_enabled = true
	}
	if usagetype_position[dbt] != 0 {
		usagetype_position_offset = uint32(usagetype_position[dbt] - 1) << 2
		usagetype_enabled = true
	}
	
	metaok = true
}
func Open(dbpath string) {
	max_ipv6_range.SetString("340282366920938463463374607431768211455", 10)
	
	var err error
	f, err = os.Open(dbpath)
	if err != nil {
		return
	}
	
	meta.databasetype = readuint8(1)
	meta.databasecolumn = readuint8(2)
	meta.databaseyear = readuint8(3)
	meta.databasemonth = readuint8(4)
	meta.databaseday = readuint8(5)
	meta.ipv4databasecount = readuint32(6)
	meta.ipv4databaseaddr = readuint32(10)
	meta.ipv6databasecount = readuint32(14)
	meta.ipv6databaseaddr = readuint32(18)
	meta.ipv4indexbaseaddr = readuint32(22)
	meta.ipv6indexbaseaddr = readuint32(26)
	meta.ipv4columnsize = uint32(meta.databasecolumn << 2) // 4 bytes each column
	meta.ipv6columnsize = uint32(16 + ((meta.databasecolumn - 1) << 2)) // 4 bytes each column, except IPFrom column which is 16 bytes
	
	dbt := meta.databasetype
	
	// since both IPv4 and IPv6 use 4 bytes for the below columns, can just do it once here
	if country_position[dbt] != 0 {
		country_position_offset = uint32(country_position[dbt] - 1) << 2
		country_enabled = true
	}
	if region_position[dbt] != 0 {
		region_position_offset = uint32(region_position[dbt] - 1) << 2
		region_enabled = true
	}
	if city_position[dbt] != 0 {
		city_position_offset = uint32(city_position[dbt] - 1) << 2
		city_enabled = true
	}
	if isp_position[dbt] != 0 {
		isp_position_offset = uint32(isp_position[dbt] - 1) << 2
		isp_enabled = true
	}
	if domain_position[dbt] != 0 {
		domain_position_offset = uint32(domain_position[dbt] - 1) << 2
		domain_enabled = true
	}
	if zipcode_position[dbt] != 0 {
		zipcode_position_offset = uint32(zipcode_position[dbt] - 1) << 2
		zipcode_enabled = true
	}
	if latitude_position[dbt] != 0 {
		latitude_position_offset = uint32(latitude_position[dbt] - 1) << 2
		latitude_enabled = true
	}
	if longitude_position[dbt] != 0 {
		longitude_position_offset = uint32(longitude_position[dbt] - 1) << 2
		longitude_enabled = true
	}
	if timezone_position[dbt] != 0 {
		timezone_position_offset = uint32(timezone_position[dbt] - 1) << 2
		timezone_enabled = true
	}
	if netspeed_position[dbt] != 0 {
		netspeed_position_offset = uint32(netspeed_position[dbt] - 1) << 2
		netspeed_enabled = true
	}
	if iddcode_position[dbt] != 0 {
		iddcode_position_offset = uint32(iddcode_position[dbt] - 1) << 2
		iddcode_enabled = true
	}
	if areacode_position[dbt] != 0 {
		areacode_position_offset = uint32(areacode_position[dbt] - 1) << 2
		areacode_enabled = true
	}
	if weatherstationcode_position[dbt] != 0 {
		weatherstationcode_position_offset = uint32(weatherstationcode_position[dbt] - 1) << 2
		weatherstationcode_enabled = true
	}
	if weatherstationname_position[dbt] != 0 {
		weatherstationname_position_offset = uint32(weatherstationname_position[dbt] - 1) << 2
		weatherstationname_enabled = true
	}
	if mcc_position[dbt] != 0 {
		mcc_position_offset = uint32(mcc_position[dbt] - 1) << 2
		mcc_enabled = true
	}
	if mnc_position[dbt] != 0 {
		mnc_position_offset = uint32(mnc_position[dbt] - 1) << 2
		mnc_enabled = true
	}
	if mobilebrand_position[dbt] != 0 {
		mobilebrand_position_offset = uint32(mobilebrand_position[dbt] - 1) << 2
		mobilebrand_enabled = true
	}
	if elevation_position[dbt] != 0 {
		elevation_position_offset = uint32(elevation_position[dbt] - 1) << 2
		elevation_enabled = true
	}
	if usagetype_position[dbt] != 0 {
		usagetype_position_offset = uint32(usagetype_position[dbt] - 1) << 2
		usagetype_enabled = true
	}
	
	metaok = true
}
// initialize the component with the database path