This project is a web application built using Go and the Gin framework. It includes features such as user authentication and database integration with PostgreSQL. Docker is used to containerize the application and manage dependencies.
- User registration and login endpoints
- PostgreSQL database integration
- Dockerized setup for easy deployment
- Environment-based configuration using
.env
- Go (version 1.23 or higher)
- Docker and Docker Compose
- PostgreSQL client tools (optional for local debugging)
git clone <repository-url>
cd <repository-name>
Create a .env
file in the root of the project and add the following configurations:
DATABASE_HOST=db
DATABASE_PORT=5432
DATABASE_USERNAME=admin
DATABASE_PASSWORD=admin
DATABASE_NAME=mydatabase
SERVER_ADDR=0.0.0.0:8080
Using Docker Compose:
docker-compose up --build
This will:
- Build the Go application.
- Start the application and PostgreSQL database in separate containers.
The application will be accessible at http://localhost:8080
.
The following API endpoints are available:
Registers a new user.
- Request Body:
{ "name": "John Doe", "email": "john@example.com", "password": "securepassword" }
- Response:
{ "message": "User registered successfully." }
Logs in a user and returns a JWT token.
- Request Body:
{ "email": "john@example.com", "password": "securepassword" }
- Response:
{ "token": "<JWT_TOKEN>" }
To connect to the PostgreSQL database locally:
psql -h localhost -U admin -d mydatabase
.
├── config # Configuration files and database connection logic
├── controller # Handlers for API endpoints
├── models # Database models
├── routes # API route definitions
├── Dockerfile # Docker image definition
├── docker-compose.yml # Docker Compose setup
├── main.go # Entry point for the application
└── .env.example # Example environment variables file
- Go: Programming language
- Gin: HTTP web framework for Go
- PostgreSQL: Relational database
- Docker: Containerization
- Application not accessible: Ensure the Go server binds to
0.0.0.0
in theSERVER_ADDR
environment variable. - Database connection failure: Verify the PostgreSQL service is running and the
.env
file contains the correct credentials.
Use the following command to view application logs:
docker-compose logs app
- Fork the repository.
- Create a new branch for your feature/bugfix.
- Commit your changes and push the branch.
- Open a pull request.
This project is licensed under the MIT License. See the LICENSE
file for details.