Simple HTTP vote collection API service in Go
Table of Contents
Clone the repo (or install via
go get) and build the project. A makefile has been included for convenience.
git clone https://github.com/dashevo/vote-collector.git cd vote-collector make
The vote collector simply logs votes to a Postgres database, therefore a running instance of the Postgres database is required as a dependency. The connection is configured via environment variables. See Configuration for more info.
.env and modify accordingly. Postgres variables need to be configured to point to an accessible, running Postgres instance.
# config cp .env.example .env vi .env # (edit accordingly) # run go run vote-collector # -or- go build ./vote-collector
The vote collector uses environment variables for configuration. Variables are read from a
.env file and can be overwritten by variables defined in the environment or directly passed to the process. See all available settings in .env.example.
docker-compose file is included for testing purposes, which also sets up a Postgres database.
cp .env.example .env vi .env # (edit accordingly) docker-compose up
curl -i http://127.0.0.1:7001/health
Generating a JWT
Some routes in the API are only available with authentication. These are the audit routes, which allow reading vote entries:
For these, a JWT token must be sent in the header (see
curl_examples.sh in this repo). There is currently no authentication table or route, so this must be manually generated.
To generate the JWT token, you can use the JWT Debugger. Simply visit the site, adjust the payload data accordingly, and in place of
your-256-bit-secret, use the value of
$JWT_SECRET_KEY that you set in the .env file (can be any secret string). Then click the "Share JWT" button to retrieve the JWT. This is the value you should send in the header after "Authorization: Bearer ".
An example JWT token looks like:
Note that this is just an example and will not work with any production deployment.
Feel free to dive in! Open an issue or submit PRs.
MIT © Dash Core Group, Inc.
There is no documentation for this package.