View documentation
Usage of ./trivia:
-e float
Token expiration (in seconds) (default 3600)
-k int
Key length (default 25)
-n string
Name of game (default "default")
-u string
URL of game websocket server (default "ws://192.168.1.96:3000")
Endpoints
/kill
/message
/notify
/query
/reset
/scoreboard
Install
$ go install
This will build and install the binary to $GOPATH/bin
.
Serve the docs
$ godoc -play
This will use the default port of 6060
. Then, point your browser to:
http://localhost:6060/pkg/github.com/btoll/trivia/pkg/trivia/
This also enables the Playground.
nginx
Service
$ cat /etc/nginx/sites-enabled/trivia
server {
server_name default_server;
location / {
proxy_pass http://127.0.0.1:3000;
}
}
$ sudo ln -s /etc/nginx/sites-enabled/trivia /etc/nginx/sites-available/trivia
systemd
Service
[Unit]
Description=Go Trivia websocket server
[Service]
Type=simple
Restart=always
RestartSec=5s
ExecStart=/path/to/go/trivia/binary
[Install]
WantedBy=multi-user.target
$ sudo systemctl daemon-reload
$ sudo systemctl start gotrivia
Test the /query
Endpoint
To send a single question to the game players, you can run the following query (of course, replace the URL
with your own) :
$ curl -XGET -H "X-TRIVIA-APIKEY: GwCcn6VZntwnI7qp1kly" \
--data "What year did the Beatles play Budokan?,B,50,1965,1968,1970" \
127.0.0.1:3000/query
An easier way would be to concatenate all of the csv
files together and then create a variable which will be incremented to pull the questions from the file line-by-line.
$ cat *.csv > game.csv
Set the variable to increment:
$ i=0
Push questions through to the game players by issuing a single chained command that first updates the variable and then uses it to pick the respective line from the game.csv
file:
$ i=$((i+1)) && curl -XGET -H "X-TRIVIA-APIKEY: GwCcn6VZntwnI7qp1kly" \
--data "$(awk 'NR=='$i'' game.csv)" \
127.0.0.1:3000/query
Binary Search Implementations
References
License
GPLv3
Author
Benjamin Toll