Documentation ¶
Index ¶
- Constants
- Variables
- func NewOracleResolver(httpClient *requests.HTTPClient, address string) *oracleResolver
- type Cache
- func (c *Cache) DetectLocation() (locationstate.Location, error)
- func (c *Cache) DetectProxyLocation(proxyPort int) (locationstate.Location, error)
- func (c *Cache) GetOrigin() locationstate.Location
- func (c *Cache) HandleConnectionEvent(se connectionstate.AppEventConnectionState)
- func (c *Cache) HandleNodeEvent(se nodevent.Payload)
- type DBResolver
- type FallbackResolver
- type OriginResolver
- type Resolver
- type ServiceLocationInfo
- type StaticResolver
Constants ¶
const LocUpdateEvent string = "location-update-event"
LocUpdateEvent is the event type used to sending or receiving event updates
Variables ¶
var ErrLocationResolutionFailed = errors.New("location resolution failed")
ErrLocationResolutionFailed represents a failure to resolve location and running out of fallbacks to try
Functions ¶
func NewOracleResolver ¶
func NewOracleResolver(httpClient *requests.HTTPClient, address string) *oracleResolver
NewOracleResolver returns new db resolver initialized from Location Oracle service
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache allows us to cache location resolution
func (*Cache) DetectLocation ¶
func (c *Cache) DetectLocation() (locationstate.Location, error)
DetectLocation returns location from cache, or fetches it if needed
func (*Cache) DetectProxyLocation ¶
func (c *Cache) DetectProxyLocation(proxyPort int) (locationstate.Location, error)
DetectProxyLocation returns the proxy location.
func (*Cache) GetOrigin ¶
func (c *Cache) GetOrigin() locationstate.Location
GetOrigin returns the origin for the user - a location that's not modified by starting services.
func (*Cache) HandleConnectionEvent ¶
func (c *Cache) HandleConnectionEvent(se connectionstate.AppEventConnectionState)
HandleConnectionEvent handles connection state change and fetches the location info accordingly. On the consumer side, we'll need to re-fetch the location once the user is connected or disconnected from a service.
func (*Cache) HandleNodeEvent ¶
HandleNodeEvent handles node state change and fetches the location info accordingly.
type DBResolver ¶
type DBResolver struct {
// contains filtered or unexported fields
}
DBResolver struct represents ip -> country resolver which uses geoip2 data reader
func NewBuiltInResolver ¶
func NewBuiltInResolver(ipResolver ip.Resolver) (*DBResolver, error)
NewBuiltInResolver returns new db resolver initialized from built in data
func NewExternalDBResolver ¶
func NewExternalDBResolver(databasePath string, ipResolver ip.Resolver) (*DBResolver, error)
NewExternalDBResolver returns Resolver which uses external country database
func (*DBResolver) DetectLocation ¶
func (r *DBResolver) DetectLocation() (loc locationstate.Location, err error)
DetectLocation detects current IP-address provides location information for the IP.
func (*DBResolver) DetectProxyLocation ¶
func (r *DBResolver) DetectProxyLocation(proxyPort int) (loc locationstate.Location, err error)
DetectProxyLocation detects proxy IP-address provides location information for the IP.
type FallbackResolver ¶
type FallbackResolver struct {
LocationResolvers []Resolver
}
FallbackResolver represents a resolver that tries multiple resolution techniques in sequence until one of them completes successfully, or all of them fail.
func NewFallbackResolver ¶
func NewFallbackResolver(resolvers []Resolver) *FallbackResolver
NewFallbackResolver returns a new instance of fallback resolver
func (*FallbackResolver) DetectLocation ¶
func (fr *FallbackResolver) DetectLocation() (locationstate.Location, error)
DetectLocation allows us to detect our current location
func (*FallbackResolver) DetectProxyLocation ¶
func (fr *FallbackResolver) DetectProxyLocation(proxyPort int) (locationstate.Location, error)
DetectProxyLocation allows us to detect our current location via a proxy.
type OriginResolver ¶
type OriginResolver interface {
GetOrigin() locationstate.Location
}
OriginResolver fetches the original country
type Resolver ¶
type Resolver interface { DetectLocation() (locationstate.Location, error) DetectProxyLocation(proxyPort int) (locationstate.Location, error) }
Resolver allows resolving location by ip
type ServiceLocationInfo ¶
ServiceLocationInfo represents data needed to determine location and if service is behind the NAT
func (ServiceLocationInfo) BehindNAT ¶
func (loc ServiceLocationInfo) BehindNAT() bool
BehindNAT checks if service is behind NAT network.
type StaticResolver ¶
type StaticResolver struct {
// contains filtered or unexported fields
}
StaticResolver struct represents country by ip ExternalDBResolver which always returns specified country
func NewFailingResolver ¶
func NewFailingResolver(err error) *StaticResolver
NewFailingResolver returns StaticResolver with entered error
func NewStaticResolver ¶
func NewStaticResolver(country, city, ipType string, ipResolver ip.Resolver) *StaticResolver
NewStaticResolver creates new StaticResolver with specified country
func (*StaticResolver) DetectLocation ¶
func (d *StaticResolver) DetectLocation() (locationstate.Location, error)
DetectLocation detects current IP-address provides location information for the IP.
func (*StaticResolver) DetectProxyLocation ¶
func (d *StaticResolver) DetectProxyLocation(_ int) (locationstate.Location, error)
DetectProxyLocation detects current IP-address provides location information for the IP.