location

package
v0.0.0-...-be0919c Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2018 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewResolverFake

func NewResolverFake(country string) *resolverFake

NewResolverFake returns resolverFake which uses statically entered country

func NewResolverFakeFailing

func NewResolverFakeFailing(err error) *resolverFake

NewResolverFakeFailing returns resolverFake with entered error

Types

type Cache

type Cache interface {
	Get() Location
	RefreshAndGet() (Location, error)
}

Cache allows caching location

func NewLocationCache

func NewLocationCache(locationDetector Detector) Cache

NewLocationCache constructs Cache

type Detector

type Detector interface {
	DetectLocation() (Location, error)
}

Detector allows detecting location by current ip

func NewDetector

func NewDetector(ipResolver ip.Resolver, locationResolver Resolver) Detector

NewDetector constructs Detector instance

func NewDetectorFake

func NewDetectorFake(ipAddress string, country string) Detector

NewDetectorFake constructs Detector instance with faked data

func NewDetectorFakeFailing

func NewDetectorFakeFailing(err error) Detector

NewDetectorFakeFailing constructs Detector instance with faked error

type Location

type Location struct {
	// IP address
	// example: 127.0.0.1
	IP string `json:"ip"`

	// example: NL
	Country string `json:"country"`
}

Location structure

type Resolver

type Resolver interface {
	ResolveCountry(ip string) (string, error)
}

Resolver allows resolving location by ip

func NewResolver

func NewResolver(databasePath string) Resolver

NewResolver returns Resolver which uses country database

Jump to

Keyboard shortcuts

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