flightranker-backend
is the back-end code for
flightranker.com. This was largely an experiment in
software organization, so there are actually three back-ends:
backendA
- a flat structure without much attention paid to writing good codebackendB
- a hierarchical structure where each dependency is isolatedbackendC
- based on ideas from John Ousterhout's A Philosophy of Software Design
All three are functionally identical. You can read more about it on my blog.
You will need to set up and populate a MySQL database before running either backend. For local development, try:
docker run -d -p 3306:3306 --name=flightdb -e MYSQL_ROOT_PASSWORD=flightdb -e MYSQL_USER=flightdb -e MYSQL_PASSWORD=flightdb -e MYSQL_DATABASE=flightdb mysql/mysql-server:5.7
The files in the sql
directory will set up the schema and populate the
airports
and carriers
tables:
cat sql/*.sql | mysql -uflightdb -pflightdb -h 127.0.0.1 flightdb
The load
program will populate the flights
table. See load/README.md
for
details. The test data was generated from a database loaded with only the
following months:
After the data has been loaded, run the SQL files in sql/updates
:
cat sql/updates/*.sql | mysql -uflightdb -pflightdb -h 127.0.0.1 flightdb
All configuration is read from environment variables, each backend reads the following:
MYSQL_ADDRESS
: Network address for the database (e.g.127.0.0.1:3306
)MYSQL_DATABASE
: Database nameMYSQL_USER
: Username for MySQLMYSQL_PASS
: Password for MySQLCORS_ALLOW_ORIGIN
: Value to return in theAccess-Control-Allow-Origin
header. If this variable is not set, the header is omitted.
Each backend can be run in the usual Go way:
cd backendA && go install && backendA
cd backendB && go install && backendB
cd backendC && go install && backendC
Database tests in all the backends require the same set of environment variables as the backend server.
MYSQL_USER=flightdb MYSQL_PASS=flightdb MYSQL_ADDRESS=127.0.0.1:3306 MYSQL_DATABASE=flightdb go test ./...
There is a Dockerfile
in root of the repository that can be used for either backend.
For backendA
:
docker build . -t flightranker-backend-a --build-arg which=backendA
For backendB
:
docker build . -t flightranker-backend-b --build-arg which=backendB
For backendC
:
docker build . -t flightranker-backend-c --build-arg which=backendC
On-Time performance data are provided by the US Bureau of Transportation Statistics.
The list of airports was taken from stat-computing.org.