Skip to content

mchatzis/go

Repository files navigation

Usage

A simple .env file has been provided.

docker compose up --build

Check all is good through Grafana at http://localhost:3000 with user-password both admin.

If you restart the container, producer will fail because it will try to create tasks in the database that already exist from the previous run. So, use -v flag to remove the volume of the db before relaunching:

docker compose down -v

Tests

go test --cover -v ./...

Most tests mock the db, but some need a real db instance. Those will fail.

Simply run:

docker compose -f docker-compose-test.yaml up -d --build

Now, you have a database instance. You just need to export the DB_URL to your terminal session:

export DB_URL=postgres://user:password@localhost:5432/golang_db_test

Now all tests should pass with go test --cover -v ./...

Design overview

Design image

ToDo

  1. Better tests, more tests.
  2. Share a bit more code between the services
  3. Rethink extendability into design
  4. Implement graceful shutdown of channels and contexts
  5. Make db operations transactional (pretty straightforward since DBTX interface supports it out-of-the-box)

About

producer-consumer pattern

Resources

Stars

Watchers

Forks

Packages

No packages published