This project demonstrates a web application built using GoLang, the Model-View-Controller (MVC) architecture, and PostgreSQL as the database. It provides a scalable, maintainable, and well-structured foundation for building robust web applications.
- MVC architecture for separation of concerns.
- PostgreSQL integration for data persistence.
- RESTful API design.
- Clean code with proper package structuring.
- Authentication using JWT (JSON Web Tokens).
- Basic CRUD operations with Bearer token access.
- Docker support for easy deployment.
- Go 1.16+ installed on your system.
- PostgreSQL 10+ installed and running.
- Docker (optional, for containerized deployment).
-
Clone the repository:
git clone https://github.com/VirendraArekar/go-postgres-boilerplate.git cd go-postgres-boilerplate git init crud
-
Set up environment variables: Create a
.env
file in the root directory to store environment variables like database credentials:DB_HOST=localhost DB_PORT=5432 DB_USER=yourusername DB_PASSWORD=yourpassword DB_NAME=yourdbname
-
Install dependencies:
go mod download
-
Set up the database: Create the database and run migrations (if any):
psql -U yourusername -d postgres -c "CREATE DATABASE yourdbname;"
-
Apply Migration: Create the database and run migrations (if any):
go run database/migrate.go -action=up # Apply All migrations go run database/migrate.go -action=down -steps=1 # Roll Back Migrations go run database/migrate.go -action=drop # Drop the database if it exists.
-
Run the application:
go run main.go
-
Access the application: Open your browser and go to
http://localhost:8080
.
POST /auth/register
: Register user.POST /auth/login
: Login user.
GET /api/users
: Fetch all users.GET /api/user/{id}
: Get a single user by ID.PUT /api/user/{id}
: Update an existing user by ID.DELETE /api/user/{id}
: Delete an user by ID.
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please submit a pull request or open an issue for any bugs or feature requests.
Virendra Arekar
Feel free to reach out at [email protected]