geolocator

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2022 License: MIT Imports: 0 Imported by: 1

README

geolocator

GoDoc MIT License

This package provides an abstract interface for using IP geolocation databases from the following providers:

Usage

To use this package in your application, begin by adding the following import:

import "github.com/nathan-osman/geolocator"

Providers are included in the subdirectories of this package. For example, to load and query an IP2Location™ database, one would use the following snippet:

import "github.com/nathan-osman/geolocator/ip2location"

provider, err := ip2location.New("path/to/file.bin")
if err != nil {
    // TODO: handle error
}
defer provider.Close()

response, err := provider.Geolocate("123.10.44.12")
if err != nil {
    // TODO: handle error
}

fmt.Printf("Country: %s\n", response.CountryName)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider interface {
	Geolocate(addr string) (*Response, error)
	Close()
}

Provider is an interface for geolocation providers to implement.

type Response

type Response struct {
	// CountryCode is the 2-character ISO code for the country.
	CountryCode string `json:"country_code"`
	// CountryName is the human-friendly name for the country.
	CountryName string `json:"country_name"`
	// Region is the name of the state / province / area within the country.
	Region string `json:"region"`
	// City is the name of the city within the region or country.
	City string `json:"city"`
	// Latitude is the geographic latitude in degrees.
	Latitude float64 `json:"latitude"`
	// Longitude is the geographic longitude in degrees.
	Longitude float64 `json:"longitude"`
	// Timezone is a timezone name from the IANA timezone database.
	Timezone string `json:"timezone"`
}

Response holds values returned from querying the database.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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