maxmindwebservice

package
v0.0.0-...-02de949 Latest Latest
Warning

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

Go to latest
Published: May 30, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package maxmindwebservice provides an OptionFactoryFunc for the backendgeopip package.

https://www.maxmind.com/en/geoip2-services-and-databases

Index

Constants

View Source
const MaxMindWebserviceBaseURL = "https://geoip.maxmind.com/geoip/v2.1/country/"

MaxMindWebserviceBaseURL defines the used base url. The IP address will be added after the last slash.

View Source
const OptionName = `webservice`

OptionName identifies this package within the register of the backendgeoip.Configuration type.

Variables

This section is empty.

Functions

func NewOptionFactory

func NewOptionFactory(hc *http.Client, userID, license cfgmodel.Str, timeout cfgmodel.Duration, redisURL cfgmodel.URL) (optionName string, _ geoip.OptionFactoryFunc)

NewOptionFactory creates a new option factory function for the MaxMind web service in the backend package to be used for automatic scope based configuration initialization. Configuration values must be set from package backendgeoip.Configuration.

First argument http.Client allows you to use a custom client when making requests to the MaxMind webservice. The timeout gets set by configuration path MaxmindWebserviceTimeout.

gob.Register(geoip.Country{}) has already been called.

func WithCountryFinder

func WithCountryFinder(t TransCacher, userID, licenseKey string, httpTimeout time.Duration) geoip.Option

WithCountryFinder uses for each incoming a request a lookup request to the Maxmind Webservice http://dev.maxmind.com/geoip/geoip2/web-services/ and caches the result in Transcacher. Hint: use package storage/transcache. If the httpTimeout is lower 0 then the default 20s get applied.

func WithCountryFinderHTTPClient

func WithCountryFinderHTTPClient(hc *http.Client, t TransCacher, userID, licenseKey string) geoip.Option

WithCountryFinderHTTPClient uses for each incoming a request a lookup request to the Maxmind Webservice http://dev.maxmind.com/geoip/geoip2/web-services/ and caches the result in Transcacher. Hint: use package storage/transcache.

Types

type TransCacher

type TransCacher interface {
	Set(key []byte, src interface{}) error
	// Get must return an errors.NotFound if a key does not exists.
	Get(key []byte, dst interface{}) error
}

TransCacher transcodes Go objects. It knows how to encode and cache any Go object and knows how to retrieve from cache and decode into a new Go object. Hint: use package storage/transcache.

type WebserviceError

type WebserviceError struct {
	Code string `json:"code,omitempty"`
	Err  string `json:"error,omitempty"`
	// contains filtered or unexported fields
}

WebserviceError used in the Maxmind Webservice functional option.

func (WebserviceError) Error

func (e WebserviceError) Error() string

Jump to

Keyboard shortcuts

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