Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var IPFallbackAddresses = []string{
"https://api.ipify.org",
"https://ip2location.io/ip",
"https://ipinfo.io/ip",
"https://api.ipify.org",
"https://ifconfig.me",
"https://www.trackip.net/ip",
"https://checkip.amazonaws.com/",
"https://icanhazip.com",
"https://ipecho.net/plain",
"https://ident.me/",
"http://whatismyip.akamai.com/",
}
IPFallbackAddresses represents the various services we can use to fetch our public IP.
Functions ¶
func RequestAndParsePlainIPResponse ¶
func RequestAndParsePlainIPResponse(c *requests.HTTPClient, url string) (string, error)
RequestAndParsePlainIPResponse requests and parses a plain IP response.
Types ¶
type CachedResolver ¶
type CachedResolver struct {
// contains filtered or unexported fields
}
CachedResolver resolves IP and caches for some duration.
func NewCachedResolver ¶
func NewCachedResolver(resolver Resolver, cacheDuration time.Duration) *CachedResolver
NewCachedResolver creates ip resolver with cache duration.
func (*CachedResolver) ClearCache ¶
func (r *CachedResolver) ClearCache()
ClearCache clears ip cache.
func (*CachedResolver) GetOutboundIP ¶
func (r *CachedResolver) GetOutboundIP() (string, error)
GetOutboundIP returns current outbound IP as string for current system.
func (*CachedResolver) GetProxyIP ¶
func (r *CachedResolver) GetProxyIP(proxyPort int) (string, error)
GetProxyIP returns proxy public IP.
func (*CachedResolver) GetPublicIP ¶
func (r *CachedResolver) GetPublicIP() (string, error)
GetPublicIP returns current public IP.
type Resolver ¶
type Resolver interface { GetOutboundIP() (string, error) GetPublicIP() (string, error) GetProxyIP(proxyPort int) (string, error) }
Resolver allows resolving current public and outbound IPs
func NewResolverMock ¶
NewResolverMock returns mockResolver which resolves statically entered IP. If multiple addresses are provided then return will depend on call order.
func NewResolverMockFailing ¶
NewResolverMockFailing returns mockResolver with entered error
func NewResolverMockMultiple ¶
NewResolverMockMultiple returns mockResolver which resolves statically entered IP. If multiple addresses are provided then return will depend on call order.
type ResolverImpl ¶
type ResolverImpl struct {
// contains filtered or unexported fields
}
ResolverImpl represents data required to operate resolving
func NewResolver ¶
func NewResolver(httpClient *requests.HTTPClient, bindAddress, url string, fallbacks []string) *ResolverImpl
NewResolver creates new ip-detector resolver with default timeout of one minute
func (*ResolverImpl) GetOutboundIP ¶
func (r *ResolverImpl) GetOutboundIP() (string, error)
GetOutboundIP returns current outbound IP as string for current system
func (*ResolverImpl) GetProxyIP ¶
func (r *ResolverImpl) GetProxyIP(proxyPort int) (string, error)
GetProxyIP returns proxy public IP
func (*ResolverImpl) GetPublicIP ¶
func (r *ResolverImpl) GetPublicIP() (string, error)
GetPublicIP returns current public IP