opensky

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

Documentation

Overview

Package opensky is the library behind the opensky command line: the HTTP client, request shaping, and the typed data models for the OpenSky Network real-time flight tracking API.

The Client paces requests to respect the anonymous rate limit (max 1 req/5s), sets a real User-Agent, adds HTTP Basic auth when credentials are supplied, and retries transient failures (429 and 5xx) with exponential backoff.

Index

Constants

View Source
const DefaultBaseURL = "https://opensky-network.org/api"

DefaultBaseURL is the root every request is built from.

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

DefaultUserAgent identifies this client to OpenSky.

View Source
const Host = "opensky-network.org"

Host is the OpenSky Network API host.

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 OpenSky Network API over HTTPS.

func NewClient

func NewClient() *Client

NewClient returns a Client with default configuration.

func NewClientWithConfig

func NewClientWithConfig(cfg Config) *Client

NewClientWithConfig returns a Client configured from cfg.

func (*Client) States

func (c *Client) States(ctx context.Context, f StatesFilter) ([]*FlightState, error)

States fetches current (or historical) flight states from the OpenSky API.

type Config

type Config struct {
	BaseURL   string
	UserAgent string
	Username  string        // optional HTTP Basic auth
	Password  string        // optional HTTP Basic auth
	Rate      time.Duration // minimum gap between requests (anonymous: 5s)
	Timeout   time.Duration
	Retries   int
}

Config holds all tunable parameters for the Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with conservative defaults suitable for the anonymous tier (max 1 request per 5 seconds, 400 API credits per day).

type Domain

type Domain struct{}

Domain is the OpenSky Network driver. It carries no state; the per-run client is built by the factory Register hands to kit.

func (Domain) Classify

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

Classify turns an ICAO24 code or an opensky-network.org URL into (type="aircraft", id=icao24).

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 canonical API URL for a given (type, id).

func (Domain) Register

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

Register installs the client factory and every operation onto app.

type FlightState

type FlightState struct {
	ICAO24         string   `json:"icao24" kit:"id"`
	Callsign       string   `json:"callsign"`
	Country        string   `json:"origin_country"`
	TimePosition   *int64   `json:"time_position,omitempty"`
	LastContact    int64    `json:"last_contact"`
	Longitude      *float64 `json:"longitude,omitempty"`
	Latitude       *float64 `json:"latitude,omitempty"`
	BaroAltitude   *float64 `json:"baro_altitude,omitempty"`
	OnGround       bool     `json:"on_ground"`
	Velocity       *float64 `json:"velocity,omitempty"`      // m/s
	TrueTrack      *float64 `json:"true_track,omitempty"`    // degrees
	VerticalRate   *float64 `json:"vertical_rate,omitempty"` // m/s
	GeoAltitude    *float64 `json:"geo_altitude,omitempty"`
	Squawk         string   `json:"squawk,omitempty"`
	SPI            bool     `json:"spi"`
	PositionSource int      `json:"position_source"` // 0=ADS-B, 1=ASTERIX, 2=MLAT, 3=FLARM
}

FlightState holds the parsed state of one aircraft as broadcast by the OpenSky Network. Fields that the aircraft has not reported are nil.

type StatesFilter

type StatesFilter struct {
	// BBox restricts to a geographic bounding box [minLat, minLon, maxLat, maxLon].
	BBox []float64
	// ICAO24 restricts to a specific aircraft transponder code.
	ICAO24 string
	// Time requests the state at a historical Unix timestamp (registered users only).
	Time int64
	// Limit caps the number of returned states. 0 = no limit.
	Limit int
}

StatesFilter holds the optional query parameters for States().

Jump to

Keyboard shortcuts

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