ip2location

package module
v0.0.0-...-4df59af Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 30, 2017 License: LGPL-3.0 Imports: 8 Imported by: 2

README

IP2Location Go Package (Idiomatic Version)

What's Different?

Compared to upstream, this fork has a number of changes we feel were necessary:

  • No global state.
  • Proper error handling (errors are not silently ignored).
  • No writing to stdout.
  • camelCase, instead of snake_case.
  • Basically, idiomatic Go (see example at the end).

Upstream Description

This Go package provides a fast lookup of country, region, city, latitude, longitude, ZIP code, time zone, ISP, domain name, connection type, IDD code, area code, weather station code, station name, mcc, mnc, mobile brand, elevation, and usage type from IP address by using IP2Location database. This package uses a file based database available at IP2Location.com. This database simply contains IP blocks as keys, and other information such as country, region, city, latitude, longitude, ZIP code, time zone, ISP, domain name, connection type, IDD code, area code, weather station code, station name, mcc, mnc, mobile brand, elevation, and usage type as values. It supports both IP address in IPv4 and IPv6.

This package can be used in many types of projects such as:

  • select the geographically closest mirror
  • analyze your web server logs to determine the countries of your visitors
  • credit card fraud detection
  • software export controls
  • display native language and currency
  • prevent password sharing and abuse of service
  • geotargeting in advertisement

The database will be updated in monthly basis for the greater accuracy. Free LITE databases are available at https://lite.ip2location.com/ upon registration.

The paid databases are available at https://www.ip2location.com under Premium subscription package.

Installation

go get github.com/getsocial-rnd/ip2location-go

Example

package main

import (
	"fmt"
	"github.com/getsocial-rnd/ip2location-go"
)

func main() {
	db, err := ip2location.Open("/path/to/db.bin")
	if err != nil {
        // handle error
	}

	results := db.GetAll(ip)
	fmt.Println(results.String())
	db.Close()
}

Dependencies

The complete database is available at http://www.ip2location.com under subscription package.

Copyright (C) 2016 by IP2Location.com, support@ip2location.com

Documentation

Index

Constants

View Source
const (
	ApiVersion string = "8.0.3"
)

Variables

View Source
var (
	ErrInvalidAddress = errors.New("Invalid IP address.")
)

Functions

This section is empty.

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

func Open

func Open(dbPath string) (*DB, error)

Open opens the database file at the given path and initializes the database.

func (*DB) Close

func (db *DB) Close() error

Close closes the database.

func (*DB) GetAll

func (db *DB) GetAll(ipaddress string) (*Record, error)

get all fields

func (*DB) GetAreaCode

func (db *DB) GetAreaCode(ipaddress string) (*Record, error)

get area code

func (*DB) GetCity

func (db *DB) GetCity(ipaddress string) (*Record, error)

get city

func (*DB) GetCountryLong

func (db *DB) GetCountryLong(ipaddress string) (*Record, error)

get country name

func (*DB) GetCountryShort

func (db *DB) GetCountryShort(ipaddress string) (*Record, error)

get country code

func (*DB) GetDomain

func (db *DB) GetDomain(ipaddress string) (*Record, error)

get domain

func (*DB) GetElevation

func (db *DB) GetElevation(ipaddress string) (*Record, error)

get elevation

func (*DB) GetIDDCode

func (db *DB) GetIDDCode(ipaddress string) (*Record, error)

get idd code

func (*DB) GetISP

func (db *DB) GetISP(ipaddress string) (*Record, error)

get isp

func (*DB) GetLatitude

func (db *DB) GetLatitude(ipaddress string) (*Record, error)

get latitude

func (*DB) GetLongitude

func (db *DB) GetLongitude(ipaddress string) (*Record, error)

get longitude

func (*DB) GetMCC

func (db *DB) GetMCC(ipaddress string) (*Record, error)

get mobile country code

func (*DB) GetMNC

func (db *DB) GetMNC(ipaddress string) (*Record, error)

get mobile network code

func (*DB) GetMobileBrand

func (db *DB) GetMobileBrand(ipaddress string) (*Record, error)

get mobile carrier brand

func (*DB) GetNetSpeed

func (db *DB) GetNetSpeed(ipaddress string) (*Record, error)

get net speed

func (*DB) GetRegion

func (db *DB) GetRegion(ipaddress string) (*Record, error)

get region

func (*DB) GetTimeZone

func (db *DB) GetTimeZone(ipaddress string) (*Record, error)

get time zone

func (*DB) GetUsageType

func (db *DB) GetUsageType(ipaddress string) (*Record, error)

get usage type

func (*DB) GetWeatherStationCode

func (db *DB) GetWeatherStationCode(ipaddress string) (*Record, error)

get weather station code

func (*DB) GetWeatherStationName

func (db *DB) GetWeatherStationName(ipaddress string) (*Record, error)

get weather station name

func (*DB) GetZipCode

func (db *DB) GetZipCode(ipaddress string) (*Record, error)

get zip code

type Record

type Record struct {
	CountryShort       string
	CountryLong        string
	Region             string
	City               string
	Isp                string
	Latitude           float32
	Longitude          float32
	Domain             string
	Zipcode            string
	TimeZone           string
	NetSpeed           string
	IddCode            string
	Areacode           string
	WeatherStationCode string
	WeatherStationName string
	Mcc                string
	Mnc                string
	MobileBrand        string
	Elevation          float32
	UsageType          string
}

func (Record) String

func (x Record) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL