geoip

package
v0.0.0-...-7e90556 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2018 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ConfigBucket        string
	IPCity              Keypath
	IPASN               Keypath
	UpdateFrequencyMins int
	JitterSecs          int
}

Config defines how a GeoLookup should be kept updated.

type GeoLookup

type GeoLookup interface {
	GetRegion(string) string
	GetCountry(string) string
	GetCity(string) string
	GetAsn(string) string
	Reload() error
}

GeoLookup defines functions to get properties of an IP address and Reload databases.

func Noop

func Noop() GeoLookup

Noop returns a GeoLookup that always returns empty strings.

type GeoMMIP

type GeoMMIP struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

GeoMMIP is a GeoLookup backed by MaxMind. Can build out a cache maybe?

func NewGeoMMIp

func NewGeoMMIp(geoLoc string, asnLoc string) (*GeoMMIP, error)

NewGeoMMIp returns a GeoMMIP using the given geo and asn database locations.

func (*GeoMMIP) GetAsn

func (g *GeoMMIP) GetAsn(ip string) string

GetAsn returns the ASN associated with the ip.

func (*GeoMMIP) GetCity

func (g *GeoMMIP) GetCity(ip string) string

GetCity returns the city associated with the ip.

func (*GeoMMIP) GetCountry

func (g *GeoMMIP) GetCountry(ip string) string

GetCountry returns the country associated with the ip.

func (*GeoMMIP) GetRegion

func (g *GeoMMIP) GetRegion(ip string) string

GetRegion returns the region associated with the ip.

func (*GeoMMIP) Reload

func (g *GeoMMIP) Reload() error

Reload reloads the configured databases.

type Keypath

type Keypath struct {
	Key  string
	Path string
}

Keypath is the combination of the s3 key to read from and the local path to write to

type NoopGeoIP

type NoopGeoIP struct{}

NoopGeoIP is a GeoLookup that always returns empty strings.

func (*NoopGeoIP) GetAsn

func (g *NoopGeoIP) GetAsn(ip string) string

GetAsn returns an empty string.

func (*NoopGeoIP) GetCity

func (g *NoopGeoIP) GetCity(ip string) string

GetCity returns an empty string.

func (*NoopGeoIP) GetCountry

func (g *NoopGeoIP) GetCountry(ip string) string

GetCountry returns an empty string.

func (*NoopGeoIP) GetRegion

func (g *NoopGeoIP) GetRegion(ip string) string

GetRegion returns an empty string.

func (*NoopGeoIP) Reload

func (g *NoopGeoIP) Reload() error

Reload does nothing.

type Updater

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

Updater keeps a GeoLookup's databases updated.

func NewUpdater

func NewUpdater(lastUpdated time.Time, geo GeoLookup, config Config, s3 s3iface.S3API) *Updater

NewUpdater returns a new Updater for the given GeoLookup.

func (*Updater) Close

func (u *Updater) Close()

Close stops the UpdateLoop for the Updater.

func (*Updater) UpdateLoop

func (u *Updater) UpdateLoop()

UpdateLoop is a blocking function that updates the GeoLookup on a recurring basis.

Jump to

Keyboard shortcuts

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