Skip to content
No description, website, or topics provided.
TSQL Go Dockerfile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
backendA
backendB Refactor duplicated code in backendB Oct 22, 2019
backendtest
load
sql Roll up flights by day Sep 11, 2019
testfiles/golden Add monthly stats Oct 16, 2019
Dockerfile Lighten the docker images a little Aug 27, 2019
README.md Set test database info from environment variables Oct 23, 2019

README.md

flightranker-backend is the back-end code for flightranker.com. This was largely an experiment in software organization, so there are actually two back-ends:

  • backendA - a flat structure without much attention paid to writing good code
  • backendB - a hierarchical structure where each dependency is isolated

Both are functionally identical. You can read more about it on my blog (once I get around to writing it, that is).

Set up

Database

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

Configuration

All configuration is read from environment variables, Both backends accept the following:

  • MYSQL_ADDRESS: Network address for the database (e.g. 127.0.0.1:3306)
  • 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-Origin header. If this variable is not set, the header is omitted.

Running

Both backends can be run in the usual Go way:

cd backendA && go install && backendA

Tests

Database tests in both 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 ./...

Docker

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-a --build-arg which=backendB

Credits

On-Time performance data are provided by the US Bureau of Transportation Statistics.

The list of airports was taken from stat-computing.org.

You can’t perform that action at this time.