Skip to content

kimh/openflights-go

 
 

Repository files navigation

CircleCI Go Report Card GoDoc MIT License

Please donate to OpenFlights!

If you do use this, I ask you to donate to OpenFlights, the source for all the data in here as of now, at http://openflights.org/donate. Seriously, if you can afford it, the OpenFlights team is responsible for putting all this data together and maintaining it, and we owe it to them to support their work.

Introduction

Note the custom import path!

import (
  "go.pedge.io/openflights"
)

Openflights is a package that exposes the data from http://openflights.org/data.html, available within https://github.com/jpatokal/openflights/tree/master/data.

Flights uses protobuf and gRPC to auto-generate a protobuf/grpc API stubs, and a HTTP/JSON API. See openflights.proto for the API definition. The HTTP endpoints should be relatively straightfoward.

The binary openflightsd is a server binary that hosts the API. make install will install this, which you can then run with ${GOPATH}/bin/openflightsd, or make launch will build a Docker image that is ~13MB as of now, and launch this Docker image with the default ports set. Then, you can curl http://0.0.0.0:8080/api/airports/code/sfo as a quick check.

The openflights package for golang adds some golang-specific additional functionality around the generated protocol buffers code. See openflights.go for publically-exposed structures.

The binaries gen-openflights-csv-store and gen-openflights-id-store will generate the data for you in either a CSVStore or IDStore. Note that this is how generated.go is generated.

The binary openflights is a CLI for the server. If OPENFLIGHTS_ADDRESS is set, this will connect to a running instance of openflightsd:

$ OPENFLIGHTS_ADDRESS=0.0.0.0:1747 openflights miles --min 500 vie-bru-ewr/mem-ord-ams-vie

Otherwise, this will create an effective server inside the CLI, doing all the initial calculations (slower):

$ openflights miles --min 500 vie-bru-ewr

The only command available right now is miles, which will calculate the miles of a route, given by space-separated airport codes. The flag --min will use a minimum miles for a segment, useful for airline mileage calculations.

$ openflights miles --min 500 vie-bru-ewr-mem-ord-ams-vie
VIE-BRU 576mi
BRU-EWR 3681mi
EWR-MEM 946mi
MEM-ORD 500mi (491mi actual)
ORD-AMS 4120mi
AMS-VIE 598mi

10421mi (10412mi actual)

Future Work

Please contact me if you want to help out!

Releases

No releases published

Packages

No packages published

Languages

  • Go 90.8%
  • Protocol Buffer 5.7%
  • Makefile 3.5%