PacktPublishing / Event-Driven-Architecture-in-Golang

Event-Driven Architecture in Golang, published by Packt
MIT License
336 stars 105 forks source link

Chapter 4 database would not connect #11

Open enoonan opened 9 months ago

enoonan commented 9 months ago

I am going through the book, just on chapter 4. When I tried to initialize a shopping basket through the Swagger UI, I got the following error:

{
  "code": 13,
  "message": "failed to connect to `host=/tmp user=mallbots_user database=mallbots`: dial error (dial unix /tmp/.s.PGSQL.5432: connect: no such file or directory)",
  "details": [
    {
      "@type": "type.googleapis.com/errors.ErrorType",
      "TypeCode": "INTERNAL_SERVER_ERROR",
      "HTTPCode": "500",
      "GRPCCode": "13"
    }
  ]
}

I was able to fix it by directly setting environment variables in the docker-compose file rather than loading via env_file:

services:
  monolith:
    ...
    environment:
    - PG_CONN=host=postgres dbname=mallbots user=mallbots_user password=mallbots_pass
    - ENVIRONMENT=development
    # env_file:
    #   - docker/.env

For some reason the .env file wasn't being read.

On MacOS Monterey 12.5

Thank you for the book BTW. Learning a ton and protobufs are blowing my mind 🤯