ipinfo

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package ipinfo is the library behind the ipinfo command line: the HTTP client, request shaping, and typed data models for the ipinfo.io IP geolocation API (https://ipinfo.io/).

The basic tier (50k lookups/month) requires no API key. The Client paces requests, sets a real User-Agent, and retries transient failures (429 and 5xx).

Index

Constants

View Source
const BaseURL = "https://" + Host

BaseURL is the root every API request is built from.

View Source
const DefaultUserAgent = "ipinfo-cli/0.1.0 (github.com/tamnd/ipinfo-cli)"

DefaultUserAgent identifies the client to ipinfo.io.

View Source
const Host = "ipinfo.io"

Host is the API hostname.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to the ipinfo.io API.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client with the given configuration.

func (*Client) BatchLookup

func (c *Client) BatchLookup(ctx context.Context, ips []string) ([]*IPInfo, error)

BatchLookup fetches geolocation info for multiple IPs, sequentially.

func (*Client) LookupIP

func (c *Client) LookupIP(ctx context.Context, ip string) (*IPInfo, error)

LookupIP fetches geolocation info for a specific IP address.

func (*Client) Me

func (c *Client) Me(ctx context.Context) (*IPInfo, error)

Me fetches geolocation info for the caller's own IP address.

type Config

type Config struct {
	BaseURL   string
	UserAgent string
	Rate      time.Duration
	Timeout   time.Duration
	Retries   int
}

Config holds all tunable parameters for the Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

type Domain

type Domain struct{}

Domain is the ipinfo driver.

func (Domain) Classify

func (Domain) Classify(input string) (string, string, error)

Classify turns an IP address into (type, id).

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, hostnames, and binary identity.

func (Domain) Locate

func (Domain) Locate(t, id string) (string, error)

Locate returns the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

type IPInfo

type IPInfo struct {
	IP       string `kit:"id" json:"ip"`
	Hostname string `json:"hostname"`
	City     string `json:"city"`
	Region   string `json:"region"`
	Country  string `json:"country"`
	Lat      string `json:"lat"` // first part of loc ("lat,lon")
	Lon      string `json:"lon"` // second part of loc ("lat,lon")
	Org      string `json:"org"`
	Postal   string `json:"postal"`
	Timezone string `json:"timezone"`
}

IPInfo holds geolocation data for an IP address.

Jump to

Keyboard shortcuts

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