ipgeolocation

package
v0.0.0-...-cebd656 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
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.

View Source
const DefaultMaxResponseBytes int64 = 256 * 1024 * 1024

Variables

ASNIncludeOptions lists every value accepted by the /v3/asn `include` parameter, in a stable canonical order.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	StatusCode int
	Message    string `json:"message"`
}

APIError represents an error response from the IPGeolocation.io API.

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) IsRetryable

func (e *APIError) IsRetryable() bool

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

type ASNResponse struct {
	IP  string     `json:"ip,omitempty"`
	ASN *ASNDetail `json:"asn"`
}

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 NewClient

func NewClient(apiKey string, opts ...Option) (*Client, error)

NewClient creates a new IPGeolocation API client.

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

func (c *Client) GetAbuseContact(ctx context.Context, ip string) (*AbuseContactResponse, error)

GetAbuseContact looks up abuse contact information for an IP.

func (*Client) GetAstronomy

func (c *Client) GetAstronomy(ctx context.Context, ip string) (*AstronomyResponse, error)

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

func (c *Client) GetSecurity(ctx context.Context, ip string) (*SecurityResponse, error)

GetSecurity looks up security/threat data for an IP via the dedicated endpoint.

func (*Client) GetTimezone

func (c *Client) GetTimezone(ctx context.Context, ip string) (*TimezoneResponse, error)

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

func (c *Client) GetTimezoneByName(ctx context.Context, tz string) (*TimezoneResponse, error)

GetTimezoneByName looks up timezone data by IANA timezone name.

func (*Client) GetUserAgent

func (c *Client) GetUserAgent(ctx context.Context, uaString string) (*UserAgentResponse, error)

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

func WithEndpoint(endpoint string) Option

WithEndpoint overrides the default API base URL.

func WithHTTPClient

func WithHTTPClient(hc *http.Client) Option

WithHTTPClient replaces the default HTTP client entirely (useful for tests).

func WithMaxResponseBytes

func WithMaxResponseBytes(n int64) Option

func WithRateLimit

func WithRateLimit(rps int) Option

WithRateLimit sets the maximum requests per second.

func WithRetries

func WithRetries(n int) Option

WithRetries sets the maximum number of retry attempts for transient errors.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets the HTTP client timeout.

func WithUserAgent

func WithUserAgent(ua string) Option

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

type SecurityResponse struct {
	IP       string    `json:"ip"`
	Security *Security `json:"security"`
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL