Skip to content

Simple HTTP vote collection API service in Go

License

Notifications You must be signed in to change notification settings

dashevo/vote-collector

Repository files navigation

vote-collector

Build Status Go Report

Simple HTTP vote collection API service in Go

Table of Contents

Install

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

Dependencies

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.

Usage

First, copy .env.example to .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

Configuration

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.

Quick start

A 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

To verify:

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:

  • /allVotes
  • /validVotes

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:

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJUZXN0IFRlc3RlcnNvbiIsInN1YiI6IkpvaG4gRG9udXQiLCJpYXQiOjE1NTE0NjYyMjN9.Z03u0ZogZZ4W2C9E7FgisQxWqp-XsnuS48JAxzRxQ1I

Note that this is just an example and will not work with any production deployment.

Maintainer

@nmarley

Contributing

Feel free to dive in! Open an issue or submit PRs.

License

MIT © Dash Core Group, Inc.

About

Simple HTTP vote collection API service in Go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published