Categorygithub.com/slavrd/go-redis-counter
modulepackage
0.8.0
Repository: https://github.com/slavrd/go-redis-counter.git
Documentation: pkg.go.dev

# README

Go redis counter package

Build Status Godoc Ref

Package rediscounter provides a simple counter that stores its value in a redis server.

The package documentation is available as godoc

The project includes basic implementations of the package:

  • a console application in folder console/ - readme.
  • a web application in folder webcounter/- readme.

Vagrant environment

The repository includes a Vagrant project that builds 3 VMs with redis server, vault server and Golang installed.

In case you are not familiar with Vagrant, a getting started guide can be found here.

Using the project

The redis VM will have redis server running on port 6379 which will be mapped to the host as well. The redis server will have password authentication configured as well.

The vault VM will have Vault installed and running in dev mode on port 8200 which will be mapped to the host as well.

The client VM will have Golang installed so the application can be built and run. The redis server IP and password will be set in the environment variables $REDIS_ADDR and $REDIS_PASS. The Vault server address and access token will be set as well in $VAULT_ADDR and $VAULT_TOKEN respectively.

Example:

vagrant up # build the VMs
vagrant ssh client # login to the client VM

# commands below are executed on the client VM

# download the counter app source code and all dependencies
go get github.com/slavrd/go-redis-counter/...

# build the console counter app
go build $(go env GOPATH)/src/github.com/slavrd/go-redis-counter/console

# run the app passing the redis password directly
./console -a $REDIS_ADDR -pass $REDIS_PASS

# run the app retrieving the redis password from Vault
./console -a $REDIS_ADDR -v-use

exit # exit from the client VM to the host

vagrant destroy # destroy the vagrant VMs

TODO

  • Console implementation
  • console: add integration with Vault KV secrets engine. Application should be able to retrieve redis password from Vault.
  • Web implementation
  • Make Vagrant mount the project in the $GOPATH of the client VM.
  • Make Vagrant use a "golang" box instead of provisioning the client VM each time.
  • Make go tests warn and stop if redis key is already set. Make it possible to force running the tests with a command flag.
  • webcounter: add a /health check method that tests the redis server connection.
  • webcounter: add a /metrics method which will report how many times each path has been requested.
  • webcounter: add a /crash method which will stop the webserver
  • webcounter: add a /reset method which will reset the counter
  • webcounter: add a /decr method which will decrease the counter by 1. Should be guarded from going below 0
  • webcounter: start even if redis connection is unavailable.
  • webcounter: implement mutual exclusion lock on redis level, so multiple app instances can be used.
  • Box with webcounter running as a service
  • Update box with webcounter service running as a non privileged user
  • webcounter: add integration with Vault KV secrets engine.
  • webcounter: update UI to call the methods with buttons.
  • packer project that creates AWS AMI with webcounter app installed as a service
  • terraform project that deploys webcounter app and its redis server in AWS
  • add network module to the terraform project
  • terraform create AWS subents in different AZs
  • replace publicly accessible webcounter EC2 instances with load balancer
  • terraform remove redis password from EC2 instances user data

Related projects

  • Vagrant counter box - a Packer project that builds a Vagrant Virtualbox box with webcounter installed as a service.
  • AWS counter AMI - a Packer project that builds an AWS AMI with webcounter installed as a service.
  • AWS redis AMI - a Packer project that build an AWS AMI with Redis server installed.
  • AWS Terraform deployment - a Terraform configuration to deploy the webcounter and redis AMIs in AWS.

# Packages

Command console starts a console client that implements the rediscounter package.
Command webcounter starts a web server that implements the rediscounter package.

# Functions

NewCounter creates a RedisCounter with the provided connection details.

# Structs

RedisCounter represents a counter that stores its value in redis.