Documentation ¶
Overview ¶
Package maxmindwebservice provides an OptionFactoryFunc for the backendgeopip package.
Index ¶
- Constants
- func NewOptionFactory(hc *http.Client, userID, license cfgmodel.Str, timeout cfgmodel.Duration, ...) (optionName string, _ geoip.OptionFactoryFunc)
- func WithCountryFinder(t TransCacher, userID, licenseKey string, httpTimeout time.Duration) geoip.Option
- func WithCountryFinderHTTPClient(hc *http.Client, t TransCacher, userID, licenseKey string) geoip.Option
- type TransCacher
- type WebserviceError
Constants ¶
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.
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