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 code
backendB- a hierarchical structure where each dependency is isolated
backendC- 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
cat sql/*.sql | mysql -uflightdb -pflightdb -h 127.0.0.1 flightdb
load program will populate the
flights table. See
details. The test data was generated from a database loaded with only the
After the data has been loaded, run the SQL files in
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.
MYSQL_DATABASE: Database name
MYSQL_USER: Username for MySQL
MYSQL_PASS: Password for MySQL
CORS_ALLOW_ORIGIN: Value to return in the
Access-Control-Allow-Originheader. 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.
docker build . -t flightranker-backend-a --build-arg which=backendA
docker build . -t flightranker-backend-b --build-arg which=backendB
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.