mdlayher/goat — pull request #24 by ChimeraCoder (2014-01-26 22:02:28+00:00)
Title: Allow remote deployments in sandboxed environments

First - thanks for writing this... my friends want to distribute some large video files that they've filmed, and this gives us a good excuse to set up a dedicated tracker.

I've made a number of fixes here, mostly related to the process of running this within sandboxed environments (eg. Heroku, Google App Engine).

* The MySQL connection assumes that the database is running on the local machine. I've added a command-line flag to specify an arbitrary MySQL DSN

* The Redis database also assumes that it is running on the local machine - I've updated it to allow for a remote database

* Both databases assume that no credentials are required - I have added a flag to specify a password for the Redis database (if needed). The MySQL credentials can be stored within the DSN, so no separate flag is needed.

* `time.Sleep` has been replaced with `time.After`, which is more reliable

* I've replaced all calls within the internal `goat` package (but not package `main`) to `os.Exit` with `panic`. Technically, non-main packages should not call either one, but `panic` is more idiomatic than `os.Exit`, as it is possible to `recover` from a panic, but `os.Exit` forces the main program to terminate, whether it wants to or not. `panic` also already returns a status code of `1` to the caller if it forces the program to terminate. Eventually, you may want to replace the `panic` calls with returned errors, but this is fine for now.

* I've modified the configuration to default to the present working directory. Offering `~/.config/goat` is fine as an option, but Go packages generally shouldn't assume they have write access outside their own directories, and this causes problems on sandboxed environments like Heroku.

* The MySQL connection will fail the first time the program is run, because the tables don't yet exist (and the program doesn't try to create them). The way I've fixed it here assumes that there is a MySQL - if you want to allow for QL databases as well, you may want to modify this patch (dc28802).