Todo App with Auth using GORM and Testcontainers
This project demonstrates a Todo application with authentication using GORM and Testcontainers.
The database is a Postgres instance created using the GoFiber's Testcontainers Service module. The instance is reused across multiple runs of the application, allowing to develop locally without having to wait for the database to be ready.
When using the air
command to run the application, the database is automatically started alongside the Fiber application, and it's automatically stopped when the air command is interrupted.
Prerequisites
Ensure you have the following installed and available in your GOPATH
:
- Golang
- Air for hot reloading
Installation
-
Clone the repository:
git clone https://github.com/gofiber/recipes.git
cd recipes/todo-app-testcontainers-postgres -
Install dependencies:
go get
Running the Application
- Start the application:
air
Environment Variables
Create a .env
file in the root directory and add the following variables:
# PORT returns the server listening port
# default: 8000
PORT=
# DB returns the name of the sqlite database
# default: postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable
# TOKENKEY returns the jwt token secret
TOKENKEY=
# TOKENEXP returns the jwt token expiration duration.
# Should be time.ParseDuration string. Source: https://golang.org/pkg/time/#ParseDuration
# default: 10h
TOKENEXP=
# TESTCONTAINERS_RYUK_DISABLED disables the Ryuk container, to avoid removing the database container when the application is stopped.
# default: true
TESTCONTAINERS_RYUK_DISABLED=true