This boilerplate provides a starting point for Go Fiber that utilizes Docker, PostgreSQL, JWT for authentication, and PgAdmin for database management.
- Docker must be installed on your system for an optimal development experience.
- Clone the repository and navigate to the project directory.
Copy the .env.example file to a new file named .env and adjust the environment variables:
DB_PORT=5432
DB_USER=example_user
DB_PASSWORD=example_password
DB_NAME=example_db
SECRET=example_secret
PGADMIN_DEFAULT_EMAIL=user@domain.com
PGADMIN_DEFAULT_PASSWORD=SecurePasswordEnsure there are no port conflicts or conflicting Docker containers running. If necessary, adjust the ports in the
.env file and docker-compose.yml.
Run the following command to start all services defined in the docker-compose.yml:
docker-compose up -dThis command will start the API, PostgreSQL database, and PgAdmin.
PgAdmin is configured to run on port 5050. Access it by navigating to http://localhost:5050 in your web browser. Login
with the PGADMIN_DEFAULT_EMAIL and PGADMIN_DEFAULT_PASSWORD specified in your .env file.
- Open PgAdmin and login.
- Right-click on 'Servers' in the left sidebar and select 'Create' -> 'Server'.
- Enter a name for the connection in the 'General' tab.
- Switch to the 'Connection' tab:
- Hostname/address:
db - Port:
5432(or your custom DB_PORT) - Username: as per
DB_USER - Password: as per
DB_PASSWORD - Save the password for ease of use.
To connect directly to the database via psql, use the script provided:
./manually_connect_to_db.shOr use Docker Compose:
docker-compose exec db psql -U <DB_USER>Replace <DB_USER> with the actual database user name from your .env file.
To create a user via the API, send a POST request to http://localhost:3000/api/user/ with the following JSON
payload:
{
"username": "johndoe",
"email": "johndoe@test.com",
"password": "1234567890"
}You can use tools like curl, Postman, or any HTTP client in your programming language of choice.
Ensure all environment variables are set correctly in your .env file, as incorrect settings may prevent the
services from starting properly.
Check the Docker logs if any service fails to start:
docker-compose logs <service-name>Replace <service-name> with web, db, or pgadmin to view logs for a specific service.
For further details, refer to the Go Fiber, Docker, and PostgreSQL documentation. This setup is ideal for development environments and should be adapted for production use with security best practices.