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, and takes inspiration from the official client.
go get github.com/ororatech/go-opensky-api
The library relies on the stdlib only, so no further dependencies are required.
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.
Create your API client:
client := opensky.NewClient("myusername", "mypassword")
// Retrieve all states.
// This query may take a long time! Filtering via function parameters is recommended.
response, err := client.GetStates(time.Time{}, nil, nil)
if err != nil {
// Something went wrong, check the error
}
fmt.Printf("received %d aircraft state objects", len(response.States))
for _, state := range response.States {
// Check the contents of each received state
}
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
}