Documentation ¶
Index ¶
- Constants
- Variables
- func ParseConfigAsLink(config *ResolverConfig) (string, error)
- type Data
- type DummyResolver
- type Edition
- type EditionData
- type EditionRule
- type EditionStatus
- type MaxMindConfig
- type MaxMindFactory
- type MaxMindResolver
- type Mock
- type Payload
- type Resolver
- type ResolverConfig
- type Service
- type Unit
- type UpdatableProxy
Constants ¶
const ( MaxmindType = "maxmind" DummyType = "dummy" UKCountry = "UK" )
const (
MaxmindPrefix = "maxmind://"
)
Variables ¶
var ( ErrInvalidLicenseKey = errors.New("Invalid license key") ErrMaxmindFileNotFound = fmt.Errorf("MaxMind DB (file with %s suffix) wasn't found", mmdbSuffix) )
var ( EmptyIP = errors.New("IP is empty") EUCountries = map[string]bool{ "BE": true, "EL": true, "LT": true, "PT": true, "BG": true, "ES": true, "LU": true, "RO": true, "CZ": true, "FR": true, "HU": true, "SI": true, "DK": true, "HR": true, "MT": true, "SK": true, "DE": true, "IT": true, "NL": true, "FI": true, "EE": true, "CY": true, "AT": true, "SE": true, "IE": true, "LV": true, "PL": true, } )
Functions ¶
func ParseConfigAsLink ¶
func ParseConfigAsLink(config *ResolverConfig) (string, error)
ParseConfigAsLink works only with MaxMindType returns MaxMind URL or error
Types ¶
type Data ¶
type Data struct { Continent string `mapstructure:"continent,omitempty" json:"continent,omitempty"` Country string `mapstructure:"country,omitempty" json:"country,omitempty"` CountryName string `mapstructure:"country_name,omitempty" json:"country_name,omitempty"` City string `mapstructure:"city,omitempty" json:"city,omitempty"` Lat float64 `mapstructure:"latitude,omitempty" json:"latitude,omitempty"` Lon float64 `mapstructure:"longitude,omitempty" json:"longitude,omitempty"` Zip string `mapstructure:"zip,omitempty" json:"zip,omitempty"` Region string `mapstructure:"region,omitempty" json:"region,omitempty"` ASN uint `mapstructure:"autonomous_system_number,omitempty" json:"autonomous_system_number,omitempty"` ASO string `mapstructure:"autonomous_system_organization,omitempty" json:"autonomous_system_organization,omitempty"` ISP string `mapstructure:"isp,omitempty" json:"isp,omitempty"` Organization string `mapstructure:"organization,omitempty" json:"organization,omitempty"` Domain string `mapstructure:"domain,omitempty" json:"domain,omitempty"` }
Data is a geo location data dto
type DummyResolver ¶
type DummyResolver struct{}
DummyResolver is a dummy resolver that does nothing and returns empty geo data
func (*DummyResolver) Close ¶
func (dr *DummyResolver) Close() error
func (*DummyResolver) Type ¶
func (dr *DummyResolver) Type() string
type Edition ¶
type Edition string
const ( //paid editions GeoIP2CountryEdition Edition = "GeoIP2-Country" GeoIP2CityEdition Edition = "GeoIP2-City" GeoIP2ISPEdition Edition = "GeoIP2-ISP" GeoIP2DomainEdition Edition = "GeoIP2-Domain" //free editions GeoLite2CityEdition Edition = "GeoLite2-City" GeoLite2CountryEdition Edition = "GeoLite2-Country" GeoLite2ASNEdition Edition = "GeoLite2-ASN" Unknown Edition = "" NotRequired Edition = "NotRequired" )
func (Edition) FreeAnalog ¶
FreeAnalog returns free database analog of the current add this to EditionRules as well
type EditionData ¶
type EditionData struct { Name Edition `json:"name"` Status EditionStatus `json:"status"` Message string `json:"message"` }
EditionData is a dto for describing edition status
type EditionRule ¶
type EditionRule struct { Main *EditionData `json:"main"` Analog *EditionData `json:"analog"` }
EditionRule is a dto for returning edition statuses
type EditionStatus ¶
type EditionStatus string
const ( StatusOK EditionStatus = "ok" StatusError EditionStatus = "error" StatusUnknown EditionStatus = "unknown" )
type MaxMindConfig ¶
type MaxMindConfig struct {
MaxMindURL string `mapstructure:"maxmind_url" json:"maxmind_url,omitempty" yaml:"maxmind_url,omitempty"`
}
MaxMindConfig is a dto for MaxMind configuration serialization
type MaxMindFactory ¶
type MaxMindFactory struct {
// contains filtered or unexported fields
}
MaxMindFactory is responsible for creation geo resolvers from
func NewMaxmindFactory ¶
func NewMaxmindFactory(officialDownloadURLTemplate string) *MaxMindFactory
func (*MaxMindFactory) Create ¶
func (f *MaxMindFactory) Create(path string) (Resolver, error)
Create creates Resolver from: 1. URL in format: maxmind://<license_key>?editions=GeoIP2-City,GeoIP2-ASN (and others) 2. direct URL for download DB 3. file path to DB 4. dir path where there is a file (DB) with mmdbSuffix
func (*MaxMindFactory) Test ¶
func (f *MaxMindFactory) Test(maxmindURL string) ([]*EditionRule, error)
Test tries to download all MaxMind databases and returns all available Edition or error if no editions are available
type MaxMindResolver ¶
type MaxMindResolver struct {
// contains filtered or unexported fields
}
MaxMindResolver is a geo location data Resolver that is based on MaxMind DB data
func (*MaxMindResolver) Close ¶
func (mmr *MaxMindResolver) Close() (multiErr error)
Close closes all parsers
func (*MaxMindResolver) Resolve ¶
func (mmr *MaxMindResolver) Resolve(ip string) (*Data, error)
Resolve returns location geo data (city, asn, domain) parsed from client ip address
func (*MaxMindResolver) Type ¶
func (mmr *MaxMindResolver) Type() string
type Payload ¶
type Payload struct {
GeoResolvers map[string]*ResolverConfig `json:"geo_data_resolvers,omitempty"`
}
type ResolverConfig ¶
type ResolverConfig struct { Type string `mapstructure:"type" json:"type,omitempty" yaml:"type,omitempty"` Config interface{} `mapstructure:"config" json:"config,omitempty" yaml:"config,omitempty"` }
ResolverConfig is a dto for geo data resolver config serialization
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service keep up-to-date geo data resolvers
func NewService ¶
func NewService(ctx context.Context, geoURL, globalGeoMaxmindPath, officialDownloadURLTemplate string) *Service
NewService returns initialized Service instance
func NewTestService ¶
NewTestService returns test instance. It is used only for tests
func (*Service) GetGeoResolver ¶
func (*Service) GetGlobalGeoResolver ¶
func (*Service) GetPaidEditions ¶
GetPaidEditions returns paidEditions
func (*Service) TestGeoResolver ¶
func (s *Service) TestGeoResolver(url string) ([]*EditionRule, error)
TestGeoResolver proxies request to the factory
type UpdatableProxy ¶
type UpdatableProxy struct {
// contains filtered or unexported fields
}
UpdatableProxy creates Resolver and re-create it every 24 hours with retry (if create fails e.g. because of connection issue)
func (*UpdatableProxy) Close ¶
func (up *UpdatableProxy) Close() error
func (*UpdatableProxy) Type ¶
func (up *UpdatableProxy) Type() string