Documentation
¶
Index ¶
- Constants
- Variables
- type APIError
- type ASN
- type ASNDetail
- type ASNRelation
- type ASNResponse
- type AbuseContact
- type AbuseContactResponse
- type AstronomyResponse
- type Client
- func (c *Client) GetASNByIP(ctx context.Context, ip string, includes ...string) (*ASNResponse, error)
- func (c *Client) GetASNByNumber(ctx context.Context, asn string, includes ...string) (*ASNResponse, error)
- func (c *Client) GetAbuseContact(ctx context.Context, ip string) (*AbuseContactResponse, error)
- func (c *Client) GetAstronomy(ctx context.Context, ip string) (*AstronomyResponse, error)
- func (c *Client) GetAstronomyByLocation(ctx context.Context, location string) (*AstronomyResponse, error)
- func (c *Client) GetIPGeolocation(ctx context.Context, ip string, includes ...string) (*IPGeolocation, error)
- func (c *Client) GetIPGeolocationBulk(ctx context.Context, ips []string, includes ...string) ([]IPGeolocation, error)
- func (c *Client) GetSecurity(ctx context.Context, ip string) (*SecurityResponse, error)
- func (c *Client) GetTimezone(ctx context.Context, ip string) (*TimezoneResponse, error)
- func (c *Client) GetTimezoneByLocation(ctx context.Context, location string) (*TimezoneResponse, error)
- func (c *Client) GetTimezoneByName(ctx context.Context, tz string) (*TimezoneResponse, error)
- func (c *Client) GetUserAgent(ctx context.Context, uaString string) (*UserAgentResponse, error)
- type Company
- type CountryMetadata
- type Currency
- type DSTDetails
- type IPGeolocation
- type Location
- type Network
- type Option
- type Security
- type SecurityResponse
- type TimeZoneInfo
- type TimezoneResponse
- type UserAgentDevice
- type UserAgentEngine
- type UserAgentInfo
- type UserAgentOS
- type UserAgentResponse
Constants ¶
const ( ASNIncludePeers = "peers" ASNIncludeUpstreams = "upstreams" ASNIncludeDownstreams = "downstreams" ASNIncludeRoutes = "routes" ASNIncludeWhoisResponse = "whois_response" )
ASNInclude* are the optional modules the /v3/asn endpoint can add to its default response through the `include` query parameter. Without any of them the API returns only the base ASN fields.
const DefaultMaxResponseBytes int64 = 256 * 1024 * 1024
Variables ¶
var ASNIncludeOptions = []string{ ASNIncludePeers, ASNIncludeUpstreams, ASNIncludeDownstreams, ASNIncludeRoutes, ASNIncludeWhoisResponse, }
ASNIncludeOptions lists every value accepted by the /v3/asn `include` parameter, in a stable canonical order.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
APIError represents an error response from the IPGeolocation.io API.
func (*APIError) IsRetryable ¶
IsRetryable returns true for transient HTTP errors that are worth retrying. A 429 is not one: it means no credits are left, and a retry cannot add credits.
type ASN ¶
type ASN struct {
ASNumber string `json:"as_number"`
Organization string `json:"organization"`
Country string `json:"country"`
Type string `json:"type,omitempty"`
Domain string `json:"domain,omitempty"`
DateAllocated string `json:"date_allocated,omitempty"`
RIR string `json:"rir,omitempty"`
}
ASN holds Autonomous System Number information.
type ASNDetail ¶
type ASNDetail struct {
ASNumber string `json:"as_number"`
Organization string `json:"organization"`
Country string `json:"country"`
Type string `json:"type"`
Domain string `json:"domain"`
DateAllocated string `json:"date_allocated"`
ASNName string `json:"asn_name"`
AllocationStatus string `json:"allocation_status"`
NumIPv4Routes string `json:"num_of_ipv4_routes"`
NumIPv6Routes string `json:"num_of_ipv6_routes"`
RIR string `json:"rir"`
// Optional modules: only present when requested through the `include`
// query parameter (see ASNIncludeOptions).
Routes []string `json:"routes,omitempty"`
Peers []ASNRelation `json:"peers,omitempty"`
Upstreams []ASNRelation `json:"upstreams,omitempty"`
Downstreams []ASNRelation `json:"downstreams,omitempty"`
WhoisResponse string `json:"whois_response,omitempty"`
}
ASNDetail holds the detailed ASN response from the dedicated /v3/asn endpoint.
type ASNRelation ¶
type ASNRelation struct {
ASNumber string `json:"as_number"`
Description string `json:"description"`
Country string `json:"country"`
}
ASNRelation represents a peer, upstream, or downstream ASN.
type ASNResponse ¶
ASNResponse is the top-level response from /v3/asn.
type AbuseContact ¶
type AbuseContact struct {
Route string `json:"route"`
Country string `json:"country"`
Name string `json:"name"`
Organization string `json:"organization"`
Kind string `json:"kind"`
Address string `json:"address"`
Emails []string `json:"emails"`
PhoneNumbers []string `json:"phone_numbers"`
}
AbuseContact holds abuse contact details for an IP's network.
It mirrors the `abuse` object returned by /v3/abuse and by /v3/ipgeo (when include=abuse is passed). Field list reference: https://ipgeolocation.io/documentation/ip-abuse-contact-api.html
type AbuseContactResponse ¶
type AbuseContactResponse struct {
IP string `json:"ip"`
Abuse *AbuseContact `json:"abuse"`
}
AbuseContactResponse wraps the /v3/abuse endpoint response.
type AstronomyResponse ¶
type AstronomyResponse struct {
Location string `json:"location,omitempty"`
IP string `json:"ip,omitempty"`
Date string `json:"date"`
Sunrise string `json:"sunrise"`
Sunset string `json:"sunset"`
SolarNoon string `json:"solar_noon"`
DayLength string `json:"day_length"`
Moonrise string `json:"moonrise"`
Moonset string `json:"moonset"`
MoonPhase float64 `json:"moon_phase"`
MoonIllumination float64 `json:"moon_illumination"`
MoonAge float64 `json:"moon_age"`
MoonAngle float64 `json:"moon_angle"`
MoonDistance float64 `json:"moon_distance"`
MoonParallacticAngle float64 `json:"moon_parallactic_angle"`
SunAltitude float64 `json:"sun_altitude"`
SunDistance float64 `json:"sun_distance"`
SunAzimuth float64 `json:"sun_azimuth"`
MoonAltitude float64 `json:"moon_altitude"`
MoonAzimuth float64 `json:"moon_azimuth"`
}
AstronomyResponse represents the response from the /v3/astronomy endpoint.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a reusable, concurrency-safe HTTP client for the IPGeolocation.io v3 API.
func (*Client) GetASNByIP ¶
func (c *Client) GetASNByIP(ctx context.Context, ip string, includes ...string) (*ASNResponse, error)
GetASNByIP looks up detailed ASN information for an IP via the dedicated endpoint.
includes selects the optional /v3/asn modules to request (see the ASNInclude* constants). With none, the API returns only the base ASN fields, which keeps the payload small; peers, upstreams, downstreams, routes and whois_response are never requested unless asked for.
func (*Client) GetASNByNumber ¶
func (c *Client) GetASNByNumber(ctx context.Context, asn string, includes ...string) (*ASNResponse, error)
GetASNByNumber looks up detailed ASN information by AS number. includes behaves as documented on GetASNByIP.
func (*Client) GetAbuseContact ¶
GetAbuseContact looks up abuse contact information for an IP.
func (*Client) GetAstronomy ¶
GetAstronomy looks up astronomical data for an IP, location, or coordinates.
func (*Client) GetAstronomyByLocation ¶
func (c *Client) GetAstronomyByLocation(ctx context.Context, location string) (*AstronomyResponse, error)
GetAstronomyByLocation looks up astronomical data for a location string.
func (*Client) GetIPGeolocation ¶
func (c *Client) GetIPGeolocation(ctx context.Context, ip string, includes ...string) (*IPGeolocation, error)
GetIPGeolocation looks up geolocation data for a single IP address. If ip is empty, the API returns data for the caller's own public IP.
func (*Client) GetIPGeolocationBulk ¶
func (c *Client) GetIPGeolocationBulk(ctx context.Context, ips []string, includes ...string) ([]IPGeolocation, error)
GetIPGeolocationBulk looks up geolocation data for multiple IP addresses in a single request.
func (*Client) GetSecurity ¶
GetSecurity looks up security/threat data for an IP via the dedicated endpoint.
func (*Client) GetTimezone ¶
GetTimezone looks up timezone data by IP address.
func (*Client) GetTimezoneByLocation ¶
func (c *Client) GetTimezoneByLocation(ctx context.Context, location string) (*TimezoneResponse, error)
GetTimezoneByLocation looks up timezone data by location string or coordinates.
func (*Client) GetTimezoneByName ¶
GetTimezoneByName looks up timezone data by IANA timezone name.
func (*Client) GetUserAgent ¶
GetUserAgent parses a user-agent string.
type Company ¶
type Company struct {
Name string `json:"name"`
Type string `json:"type"`
Domain string `json:"domain"`
}
Company holds the company/ISP information for the IP.
type CountryMetadata ¶
type CountryMetadata struct {
CallingCode string `json:"calling_code"`
TLD string `json:"tld"`
Languages []string `json:"languages"`
}
CountryMetadata holds country-level metadata.
type Currency ¶
type Currency struct {
Code string `json:"code"`
Name string `json:"name"`
Symbol string `json:"symbol"`
}
Currency holds the currency associated with the IP's country.
type DSTDetails ¶
type DSTDetails struct {
UTCTime string `json:"utc_time"`
Duration string `json:"duration"`
Gap bool `json:"gap"`
DateTimeAfter string `json:"date_time_after"`
DateTimeBefore string `json:"date_time_before"`
Overlap bool `json:"overlap"`
}
DSTDetails holds the details for a DST transition.
type IPGeolocation ¶
type IPGeolocation struct {
IP string `json:"ip"`
Domain string `json:"domain,omitempty"`
Hostname string `json:"hostname,omitempty"`
Location *Location `json:"location,omitempty"`
CountryMetadata *CountryMetadata `json:"country_metadata,omitempty"`
Network *Network `json:"network,omitempty"`
Currency *Currency `json:"currency,omitempty"`
ASN *ASN `json:"asn,omitempty"`
Company *Company `json:"company,omitempty"`
Security *Security `json:"security,omitempty"`
Abuse *AbuseContact `json:"abuse,omitempty"`
TimeZone *TimeZoneInfo `json:"time_zone,omitempty"`
UserAgent *UserAgentInfo `json:"user_agent,omitempty"`
}
IPGeolocation represents the full response from the /v3/ipgeo endpoint.
type Location ¶
type Location struct {
ContinentCode string `json:"continent_code"`
ContinentName string `json:"continent_name"`
CountryCode2 string `json:"country_code2"`
CountryCode3 string `json:"country_code3"`
CountryName string `json:"country_name"`
CountryNameOfficial string `json:"country_name_official"`
CountryCapital string `json:"country_capital"`
StateProv string `json:"state_prov"`
StateCode string `json:"state_code"`
District string `json:"district"`
City string `json:"city"`
Locality string `json:"locality,omitempty"`
AccuracyRadius string `json:"accuracy_radius,omitempty"`
Confidence string `json:"confidence,omitempty"`
DMACode string `json:"dma_code,omitempty"`
Zipcode string `json:"zipcode"`
Latitude string `json:"latitude"`
Longitude string `json:"longitude"`
IsEU bool `json:"is_eu"`
CountryFlag string `json:"country_flag"`
GeonameID string `json:"geoname_id"`
CountryEmoji string `json:"country_emoji"`
}
Location holds geographic location data.
type Network ¶
type Network struct {
ConnectionType string `json:"connection_type"`
Route string `json:"route"`
IsAnycast bool `json:"is_anycast"`
IsCDN bool `json:"is_cdn"`
CDNProviderName string `json:"cdn_provider_name"`
}
Network holds network/route information.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithEndpoint ¶
WithEndpoint overrides the default API base URL.
func WithHTTPClient ¶
WithHTTPClient replaces the default HTTP client entirely (useful for tests).
func WithMaxResponseBytes ¶
func WithRateLimit ¶
WithRateLimit sets the maximum requests per second.
func WithRetries ¶
WithRetries sets the maximum number of retry attempts for transient errors.
func WithTimeout ¶
WithTimeout sets the HTTP client timeout.
func WithUserAgent ¶
WithUserAgent sets the User-Agent header on every request.
type Security ¶
type Security struct {
ThreatScore int `json:"threat_score"`
IsTor bool `json:"is_tor"`
IsProxy bool `json:"is_proxy"`
ProxyProviderNames []string `json:"proxy_provider_names"`
ProxyConfidenceScore int `json:"proxy_confidence_score"`
ProxyLastSeen string `json:"proxy_last_seen"`
IsResidentialProxy bool `json:"is_residential_proxy"`
IsVPN bool `json:"is_vpn"`
VPNProviderNames []string `json:"vpn_provider_names"`
VPNConfidenceScore int `json:"vpn_confidence_score"`
VPNLastSeen string `json:"vpn_last_seen"`
IsRelay bool `json:"is_relay"`
RelayProviderName string `json:"relay_provider_name"`
IsAnonymous bool `json:"is_anonymous"`
IsKnownAttacker bool `json:"is_known_attacker"`
IsBot bool `json:"is_bot"`
BotConfidenceScore int `json:"bot_confidence_score"`
BotOperatorName string `json:"bot_operator_name"`
BotType string `json:"bot_type"`
IsKnownGoodBot bool `json:"is_known_good_bot"`
BotLastSeen string `json:"bot_last_seen"`
IsSpam bool `json:"is_spam"`
IsCloudProvider bool `json:"is_cloud_provider"`
CloudProviderName string `json:"cloud_provider_name"`
IsCorporateGateway bool `json:"is_corporate_gateway"`
CorporateGatewayType string `json:"corporate_gateway_type"`
CorporateGatewayProviderName string `json:"corporate_gateway_provider_name"`
}
Security holds IP security / threat intelligence data.
It mirrors the `security` object returned by /v3/security and by /v3/ipgeo (when include=security is passed). Field list reference: https://ipgeolocation.io/documentation/ip-security-api.html
type SecurityResponse ¶
SecurityResponse wraps the /v3/security endpoint response.
type TimeZoneInfo ¶
type TimeZoneInfo struct {
Name string `json:"name"`
Offset float64 `json:"offset"`
OffsetWithDST float64 `json:"offset_with_dst"`
CurrentTime string `json:"current_time"`
CurrentTimeUnix float64 `json:"current_time_unix"`
CurrentTZAbbreviation string `json:"current_tz_abbreviation"`
CurrentTZFullName string `json:"current_tz_full_name"`
StandardTZAbbreviation string `json:"standard_tz_abbreviation"`
StandardTZFullName string `json:"standard_tz_full_name"`
IsDST bool `json:"is_dst"`
DSTSavings float64 `json:"dst_savings"`
DSTExists bool `json:"dst_exists"`
DSTTZAbbreviation string `json:"dst_tz_abbreviation"`
DSTTZFullName string `json:"dst_tz_full_name"`
DSTStart *DSTDetails `json:"dst_start,omitempty"`
DSTEnd *DSTDetails `json:"dst_end,omitempty"`
}
TimeZoneInfo holds timezone data returned within the ipgeo or timezone endpoint.
type TimezoneResponse ¶
type TimezoneResponse struct {
Timezone string `json:"timezone"`
IP string `json:"ip,omitempty"`
Location *Location `json:"location,omitempty"`
TimeZone *TimeZoneInfo `json:"time_zone,omitempty"`
}
TimezoneResponse represents the full response from the /v3/timezone endpoint.
type UserAgentDevice ¶
type UserAgentDevice struct {
Name string `json:"name"`
Type string `json:"type"`
Brand string `json:"brand"`
CPU string `json:"cpu"`
}
UserAgentDevice holds device info from the user-agent parser.
type UserAgentEngine ¶
type UserAgentEngine struct {
Name string `json:"name"`
Type string `json:"type"`
Version string `json:"version"`
VersionMajor string `json:"version_major"`
}
UserAgentEngine holds rendering engine info.
type UserAgentInfo ¶
type UserAgentInfo struct {
UserAgentString string `json:"user_agent_string"`
Name string `json:"name"`
Type string `json:"type"`
Version string `json:"version"`
VersionMajor string `json:"version_major"`
Device *UserAgentDevice `json:"device,omitempty"`
Engine *UserAgentEngine `json:"engine,omitempty"`
OperatingSystem *UserAgentOS `json:"operating_system,omitempty"`
}
UserAgentInfo holds parsed user-agent details.
type UserAgentOS ¶
type UserAgentOS struct {
Name string `json:"name"`
Type string `json:"type"`
Version string `json:"version"`
VersionMajor string `json:"version_major"`
Build string `json:"build"`
}
UserAgentOS holds OS info from the user-agent parser.
type UserAgentResponse ¶
type UserAgentResponse struct {
UserAgentString string `json:"user_agent_string"`
Name string `json:"name"`
Type string `json:"type"`
Version string `json:"version"`
VersionMajor string `json:"version_major"`
Device *UserAgentDevice `json:"device,omitempty"`
Engine *UserAgentEngine `json:"engine,omitempty"`
OperatingSystem *UserAgentOS `json:"operating_system,omitempty"`
}
UserAgentResponse represents the full response from /v3/user-agent.