opensky

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: MIT Imports: 7 Imported by: 0

README

OpenSky Network API

This repository contains a community API client implementation in Golang for the OpenSky Network. It is used to retrieve live and historical details about aircraft positioning and flight information.

The library is based on the REST API docs.

Implemented only getting historical data without State Vectors.

Installation

go get github.com/invander/go-opensky-api

The library relies on the stdlib only, so no further dependencies are required.

User Account

The client does not strictly require an account to use the OpenSky API. Username and password are, therefore, optional!

Refer to the limitations, to see why/when a user account would be preferred.

Usage

Create your API client:

client := opensky.NewClient("myusername", "mypassword")
Get Flights
flights, err := client.GetFlights(time.Now().Add(-2*time.Hour), time.Now())
if err != nil {
    // Something went wrong, check the error
}
fmt.Printf("received %d flight objects", len(flights))
for _, flight := range flights {
	// Check the contents of each received flight
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallSignTrim

type CallSignTrim string

func (*CallSignTrim) UnmarshalJSON

func (c *CallSignTrim) UnmarshalJSON(data []byte) error

type Client

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

Client An OpenSky API client.

func NewClient

func NewClient(username string, password string) *Client

NewClient Creates a new OpenSky client. Username and password fields are optional.

func (*Client) GetFlights

func (c *Client) GetFlights(begin time.Time, end time.Time) (flights []Flight, err error)

GetFlights retrieves all flight information within a certain time interval. Flights departed and arrived within the [begin, end] boundaries will be returned.

If no flights were found for the given time period, a 404 error will be returned instead.

func (*Client) GetFlightsByAircraft

func (c *Client) GetFlightsByAircraft(icao24 string, begin time.Time, end time.Time) (flights []Flight, err error)

GetFlightsByAircraft retrieves flight information for a particular aircraft, identified by the icao24 address parameter, within a certain time interval. Flights departed and arrived within the [begin, end] boundaries will be returned.

If no flights were found for the given time period, a 404 error will be returned instead.

func (*Client) GetFlightsByArrival

func (c *Client) GetFlightsByArrival(airport string, begin time.Time, end time.Time) (flights []Flight, err error)

GetFlightsByArrival retrieve flights for a certain airport which arrived within a given time interval [begin, end].

If no flights were found for the given time period, a 404 error will be returned instead.

func (*Client) GetFlightsByDeparture

func (c *Client) GetFlightsByDeparture(airport string, begin time.Time, end time.Time) (flights []Flight, err error)

GetFlightsByDeparture retrieve flights for a certain airport which departed within a given time interval [begin, end].

If no flights were found for the given time period, a 404 error will be returned instead.

func (*Client) GetFlightsByInterval

func (c *Client) GetFlightsByInterval(begin time.Time, end time.Time) (flights []Flight, err error)

GetFlightsByInterval retrieves flights for a certain time interval [begin, end].

If no flights were found for the given time period, a 404 error will be returned instead.

func (*Client) GetTrackByAircraft

func (c *Client) GetTrackByAircraft(icao24 string, time time.Time) (response GetTracksResponse, err error)

GetTrackByAircraft Retrieve the trajectory for a certain aircraft at a given time. The trajectory is a list of waypoints containing position, barometric altitude, true track and an on-ground flag.

If no flights were found for the given time period, a 404 error will be returned instead.

type Flight

type Flight struct {
	Icao24                           string       `json:"icao24"`
	FirstSeen                        int          `json:"firstSeen"`
	EstDepartureAirport              string       `json:"estDepartureAirport"`
	LastSeen                         int          `json:"lastSeen"`
	EstArrivalAirport                string       `json:"estArrivalAirport"`
	Callsign                         CallSignTrim `json:"callsign"`
	EstDepartureAirportHorizDistance int          `json:"estDepartureAirportHorizDistance"`
	EstDepartureAirportVertDistance  int          `json:"estDepartureAirportVertDistance"`
	EstArrivalAirportHorizDistance   int          `json:"estArrivalAirportHorizDistance"`
	EstArrivalAirportVertDistance    int          `json:"estArrivalAirportVertDistance"`
	DepartureAirportCandidatesCount  int          `json:"departureAirportCandidatesCount"`
	ArrivalAirportCandidatesCount    int          `json:"arrivalAirportCandidatesCount"`
}

type GetTracksResponse

type GetTracksResponse struct {
	Icao24    string     `json:"icao24"`
	Callsign  string     `json:"callsign"`
	StartTime time.Time  `json:"startTime"`
	EndTime   time.Time  `json:"endTime"`
	Paths     []Waypoint `json:"path"`
}

type Waypoint

type Waypoint struct {
	Time         time.Time `json:"time"`
	Latitude     *float64  `json:"latitude"`
	Longitude    *float64  `json:"longitude"`
	BaroAltitude *float64  `json:"baro_altitude"`
	TrueTrack    *float64  `json:"true_track"`
	OnGround     bool      `json:"on_ground"`
}

Jump to

Keyboard shortcuts

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