clientgeo

package
v0.15.8 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package clientgeo supports interfaces to different data sources to help identify client geo location for server selection.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBadLatLonFormat is returned with a lat,lon header is missing or corrupt.
	ErrBadLatLonFormat = errors.New("lat,lon format was missing or corrupt")

	// ErrNullLatLon is returned with a 0,0 lat/lon value is provided.
	ErrNullLatLon = errors.New("lat,lon value was null: " + nullLatLon)
)
View Source
var (
	ErrNoUserParameters       = errors.New("no user location parameters provided")
	ErrUnusableUserParameters = errors.New("user provided location parameters were unusable")
)

Error values returned by Locate.

Functions

This section is empty.

Types

type AppEngineLocator

type AppEngineLocator struct{}

AppEngineLocator finds a client location using AppEngine headers for lat/lon, region, or country.

func NewAppEngineLocator

func NewAppEngineLocator() *AppEngineLocator

NewAppEngineLocator creates a new AppEngineLocator.

func (*AppEngineLocator) Locate

func (sl *AppEngineLocator) Locate(req *http.Request) (*Location, error)

Locate finds a location for the given client request using AppEngine headers. If no location is found, an error is returned.

func (*AppEngineLocator) Reload

func (sl *AppEngineLocator) Reload(ctx context.Context)

Reload does nothing.

type Location

type Location struct {
	Latitude  string
	Longitude string
	Headers   http.Header
}

Location contains an estimated the latitude and longitude of a client IP.

type Locator

type Locator interface {
	Locate(req *http.Request) (*Location, error)
	Reload(context.Context)
}

Locator supports locating a client request and Reloading the underlying database.

type MaxmindLocator

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

MaxmindLocator manages access to the maxmind database.

func NewMaxmindLocator

func NewMaxmindLocator(ctx context.Context, mm content.Provider) *MaxmindLocator

NewMaxmindLocator creates a new MaxmindLocator and loads the current copy of MaxMind data stored in GCS.

func (*MaxmindLocator) Locate

func (mml *MaxmindLocator) Locate(req *http.Request) (*Location, error)

Locate finds the Location of the given request using client's remote IP or IP from X-Forwarded-For header.

func (*MaxmindLocator) Reload

func (mml *MaxmindLocator) Reload(ctx context.Context)

Reload is intended to be regularly called in a loop. It should check whether the data in GCS is newer than the local data, and, if it is, then download and load that new data into memory and then replace it in the annotator.

type MultiLocator

type MultiLocator []Locator

MultiLocator wraps several Locator types into the Locate interface.

func (MultiLocator) Locate

func (g MultiLocator) Locate(req *http.Request) (*Location, error)

Locate calls Locate on all client Locators. The first successfully identifiec location is returned. If all Locators returns an error, a multierror.Error is returned as an error with all Locator error messages.

func (MultiLocator) Reload

func (g MultiLocator) Reload(ctx context.Context)

Reload calls Reload on all Client Locators.

type NullLocator

type NullLocator struct{}

NullLocator always returns a client location of 0,0.

func (*NullLocator) Locate

func (f *NullLocator) Locate(req *http.Request) (*Location, error)

Locate returns the static 0,0 lat/lon location.

func (*NullLocator) Reload

func (f *NullLocator) Reload(ctx context.Context)

Reload does nothing.

type UserLocator

type UserLocator struct{}

UserLocator definition for accepting user provided location hints.

func NewUserLocator

func NewUserLocator() *UserLocator

NewUserLocator creates a new UserLocator.

func (*UserLocator) Locate

func (u *UserLocator) Locate(req *http.Request) (*Location, error)

Locate looks for user-provided parameters to specify the client location.

func (*UserLocator) Reload

func (u *UserLocator) Reload(ctx context.Context)

Reload does nothing.

Jump to

Keyboard shortcuts

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