This is a fully functional E-commerce Backend built using Go, Gin, and GORM. It includes authentication, product management, order management, and a review & ratings system.
- User Authentication (JWT-based)
- Product Management (CRUD operations)
- Cart & Orders (Add to cart, checkout, track orders)
- Swagger API Documentation
- Secure with Middleware (Auth & Role-based Access Control)
- Backend: Go (Gin framework)
- Database: PostgreSQL (GORM ORM)
- Authentication: JWT (JSON Web Tokens)
- API Documentation: Swagger
git clone https://github.com/telman/ecom-go.git
cd ecom
go mod tidy
Create a .env
file and add:
DB_HOST=localhost
DB_USER=youruser
DB_PASSWORD=yourpassword
DB_NAME=ecom_db
DB_PORT=5432
JWT_SECRET=your_secret_key
go run main.go migrate
go run main.go
Server will run on http://localhost:8080
Swagger UI is available at:
http://localhost:8080/swagger/index.html
To regenerate Swagger docs, run:
swag init
Method | Endpoint | Description |
---|---|---|
POST | /auth/register | Register a new user |
POST | /auth/login | Login user and get JWT |
GET | /user/profile | Get user profile |
Method | Endpoint | Description |
---|---|---|
POST | /products/add | Add a new product (Admin) |
GET | /products | Get all products |
GET | /products/:id | Get product details |
PUT | /products/:id | Update product (Admin) |
DELETE | /products/:id | Delete product (Admin) |
Method | Endpoint | Description |
---|---|---|
POST | /cart/add | Add product to cart |
GET | /cart | View cart items |
POST | /orders/place | Place an order |
GET | /orders | Get user orders |
PATCH | /orders/:id/status | Update order status (Admin) |
/ecom-backend
βββ controllers/ # API handlers
βββ middleware/ # JWT authentication middleware
βββ models/ # Database models (GORM)
βββ routes/ # API route definitions
βββ db/ # Database connection
βββ main.go # Entry point
βββ go.mod # Go module file
βββ swagger.json # API documentation
Feel free to fork and contribute! Open an issue or submit a PR.
This project is licensed under the MIT License.
Happy Coding! π