Libraries to "go get"
- github.com/lib/pq
- CREATE USER maxrussell PASSWORD 'somepassword';
- CREATE DATABASE rpsls WITH OWNER maxrussell;
- CREATE TABLE scoreboard( username varchar(12) PRIMARY KEY NOT NULL, score int NOT NULL );
- GRANT SELECT, UPDATE, INSERT ON scoreboard TO maxrussell;
- go test github.com/maxrussell/rpsls/...
- Build the two applications:
- go install github.com/maxrussell/rpsls/game
- go install github.com/maxrussell/rpsls/scoreboard
- Run the two applications:
- DBHOST=localhost DBUSER=maxrussell DBPASS=somepassword DBDATABASE=rpsls $GOBIN/scoreboard
- SCOREBOARD='http://localhost:8081' $GOBIN/game
- For the sake of time saving, the game serves HTTP on port 8080 and the scoreboard on 8081
- Check out the available choices by hitting http://localhost:8080/choices
- Play the game a bit by making requests to the game in your favorite HTTP client. Personally, I use Postman. For example: http://localhost:8080/play?player=grace&computer=ada&choice=1
- Check out the scoreboard by hitting http://localhost:8081/scoreboard
The environment variable SCOREBOARD is optional and tells the game where the scoreboard is. If found, the game automatically posts results to the scoreboard. This environment variable's value should be of the form "http://localhost:8081". If not supplied, results will need to be posted to the scoreboard separately.