Documentation
¶
Overview ¶
Package ipwho is the library behind the ipwho command line: the HTTP client, request shaping, and the typed data models for ipwho.is.
The Client here is the spine every command shares. It sets a real User-Agent, paces requests so a busy session stays polite, and retries the transient failures (429 and 5xx) that any public API throws under load.
Index ¶
Constants ¶
const BaseURL = "https://" + Host
BaseURL is the root every request is built from.
const DefaultUserAgent = "ipwho/dev (+https://github.com/tamnd/ipwho-cli)"
DefaultUserAgent identifies the client to ipwho.is.
const Host = "ipwho.is"
Host is the site this client talks to.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
HTTP *http.Client
UserAgent string
// Rate is the minimum gap between requests. Zero means no pacing.
Rate time.Duration
Retries int
// contains filtered or unexported fields
}
Client talks to ipwho.is over HTTP.
func NewClient ¶
func NewClient() *Client
NewClient returns a Client with sensible defaults: a 30s timeout, a 200ms minimum gap between requests, and five retries on transient errors.
func (*Client) Lookup ¶
Lookup fetches geolocation info for the given IP address. If ip is empty, the API returns info for your own IP.
type Connection ¶
type Connection struct {
ASN int `json:"asn"`
Org string `json:"org"`
ISP string `json:"isp"`
Domain string `json:"domain"`
}
Connection holds the ASN and organization details for an IP.
type Domain ¶
type Domain struct{}
Domain is the ipwho driver. It carries no state; the per-run client is built by the factory Register hands kit.
func (Domain) Classify ¶
Classify turns any accepted input into the canonical (type, id). An input that looks like an IP address (contains dots or colons with digits) is classified as "ip"; anything else is treated as a search query.
func (Domain) Info ¶
func (Domain) Info() kit.DomainInfo
Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.
type IPInfo ¶
type IPInfo struct {
IP string `kit:"id" json:"ip"`
Type string `json:"type"`
Continent string `json:"continent"`
Country string `json:"country"`
CountryCode string `json:"country_code"`
Region string `json:"region"`
RegionCode string `json:"region_code"`
City string `json:"city"`
Postal string `json:"postal"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
IsEU bool `json:"is_eu"`
CallingCode string `json:"calling_code"`
Capital string `json:"capital"`
Connection Connection `json:"connection"`
Timezone Timezone `json:"timezone"`
}
IPInfo is the full geolocation record for an IP address.