ipapi

package
v0.1.2 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 ipapi is the library behind the ipapi command line: the HTTP client, request shaping, and the typed data models for the ip-api.com IP geolocation API.

No API key or authentication is required. The free tier is limited to 45 requests per minute. Note: the free tier uses HTTP (not HTTPS).

Index

Constants

View Source
const (
	// DefaultUserAgent identifies the client to the server.
	DefaultUserAgent = "ipapi-cli/dev (+https://github.com/tamnd/ipapi-cli)"

	// Host is the site this client talks to.
	Host = "ip-api.com"
)

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 ip-api.com API over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) Batch added in v0.1.1

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

Batch fetches geolocation data for a slice of IP addresses in one POST request. The batch endpoint is documented to accept up to 100 IPs per call.

func (*Client) Lookup added in v0.1.1

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

Lookup fetches geolocation data for the given IP address. If ip is empty, the API returns data for the caller's own public IP. Returns an error if the API responds with status "fail".

type Config added in v0.1.1

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 added in v0.1.1

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults for the ip-api.com API. Note: the free tier uses HTTP (not HTTPS) and is rate-limited to 45 req/min.

type Domain

type Domain struct{}

Domain is the ipapi driver.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns an input into the canonical (type, id).

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.

func (Domain) Locate

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

Locate returns the live http 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 added in v0.1.1

type IPInfo struct {
	Query       string  `json:"query"        kit:"id"`
	Status      string  `json:"status"`
	Country     string  `json:"country"`
	CountryCode string  `json:"country_code"`
	RegionName  string  `json:"region_name"`
	City        string  `json:"city"`
	Zip         string  `json:"zip"`
	Lat         float64 `json:"lat"`
	Lon         float64 `json:"lon"`
	Timezone    string  `json:"timezone"`
	ISP         string  `json:"isp"`
	Org         string  `json:"org"`
	AS          string  `json:"as"`
}

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