way

package module
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2022 License: GPL-3.0 Imports: 10 Imported by: 0

README

go-way

Golang postal level geo-lookup library.

Installation

go-way may be installed using the go get command:

go get github.com/pghq/go-way

Usage

import "github.com/pghq/go-way"

To create a new client:

radar := way.New()

// optionally wait for background refresh to occur
radar.Wait()
if err := radar.Error(); err != nil{
    panic(err)
}

loc, err := radar.IP("1.2.3.4")
if err != nil{
    panic(err)
}

loc, err = radar.City(country.UnitedStatesAmerica, "NY", "Brooklyn")
if err != nil{
    panic(err)
}

loc, err = radar.Postal(country.UnitedStatesAmerica, "NY", "10027")
if err != nil{
    panic(err)
}

Powered by

Documentation

Overview

Package way provides a client for postal code lookups.

Index

Constants

View Source
const (
	// DefaultGeonamesLocation is the default origin location for the GeoName export
	DefaultGeonamesLocation = "https://download.geonames.org/export/zip/allCountries.zip"

	// DefaultMaxmindLocation is the default origin location for the Maxmind export
	DefaultMaxmindLocation = "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=YOUR_LICENSE_KEY&suffix=tar.gz"

	// DefaultRefreshTimeout is the default wait time for refreshing locations
	DefaultRefreshTimeout = 5 * time.Minute
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Radar added in v0.0.5

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

Radar is a postal level geo-lookup service.

func New added in v0.0.6

func New(opts ...RadarOption) *Radar

New creates a new radar instance.

func (*Radar) City added in v0.0.5

func (r *Radar) City(country country.Country, subdivision1, city string) (*geonames.Location, error)

City lookup

func (*Radar) Country added in v0.0.5

func (r *Radar) Country(country country.Country) (*geonames.Location, error)

Country lookup

func (*Radar) Error added in v0.0.5

func (r *Radar) Error() error

Error gets any background errors

func (*Radar) IP added in v0.0.5

func (r *Radar) IP(addr string) (*geonames.Location, error)

IP lookup

func (*Radar) PSD added in v0.0.6

func (r *Radar) PSD(country country.Country, subdivision1 string) (*geonames.Location, error)

PSD primary subdivision lookup

func (*Radar) Postal added in v0.0.5

func (r *Radar) Postal(country country.Country, postal string) (*geonames.Location, error)

Postal lookup

func (*Radar) Refresh added in v0.0.5

func (r *Radar) Refresh()

Refresh locations

func (*Radar) SSD added in v0.0.6

func (r *Radar) SSD(country country.Country, subdivision1, subdivision2 string) (*geonames.Location, error)

SSD secondary division lookup

type RadarOption added in v0.0.6

type RadarOption func(r *Radar)

RadarOption to configure custom radar

func Countries added in v0.0.15

func Countries(o ...string) RadarOption

Countries supported

func GeonamesLocation

func GeonamesLocation(o string) RadarOption

GeonamesLocation sets a custom location to refresh geonames db from

func MaxmindKey

func MaxmindKey(o string) RadarOption

MaxmindKey sets a custom maxmind licence key

func MaxmindLocation

func MaxmindLocation(o string) RadarOption

MaxmindLocation sets a custom location to refresh maxmind db from

func RefreshTimeout

func RefreshTimeout(o time.Duration) RadarOption

RefreshTimeout sets a custom refresh timeout

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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