geojs

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: 9 Imported by: 0

Documentation

Overview

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

No API key is required. 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 Host = "get.geojs.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 GeoJS API.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client with the given configuration.

func (*Client) LookupIP

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

LookupIP fetches geolocation info for a specific IP address.

func (*Client) MyGeo

func (c *Client) MyGeo(ctx context.Context) (*GeoInfo, error)

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

func (*Client) MyIP

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

MyIP fetches only the caller's public 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 geojs driver. It carries no state; the per-run client is built by the factory Register hands kit.

func (Domain) Classify

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

Classify turns an IP address string into (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(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 GeoInfo

type GeoInfo struct {
	IP           string `json:"ip"           kit:"id"`
	Country      string `json:"country"`
	CountryCode  string `json:"country_code"`
	Region       string `json:"region"`
	City         string `json:"city"`
	Latitude     string `json:"latitude"`
	Longitude    string `json:"longitude"`
	Timezone     string `json:"timezone"`
	ASN          string `json:"asn"`
	Organization string `json:"organization"`
}

GeoInfo holds geolocation data for an IP address.

type IPInfo

type IPInfo struct {
	IP string `json:"ip" kit:"id"`
}

IPInfo holds just the public IP address.

Jump to

Keyboard shortcuts

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