A fully functional e-commerce backend built with Golang, PostgreSQL, and JWT authentication.
This project is designed to power a modern e-commerce platform with features like product management, user authentication, and order handling.
- Language: Go (Golang)
- Database: PostgreSQL
- Query:
database/sql+pgxdriver - Authentication: JWT (JSON Web Token)
- Password Hashing: bcrypt
- API Format: RESTful JSON
- Architecture: Domain-driven design
- Environment Management:
.envfile - Dependency Management: Go Modules
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/auth/register |
Register a new user |
POST |
/api/auth/login |
Login user and receive JWT token |
| Method | Endpoint | Description | Access |
|---|---|---|---|
GET |
/api/products |
Get all products | Public |
GET |
/api/products/:id |
Get product by ID | Public |
POST |
/api/products |
Create product | Admin |
PUT |
/api/products/:id |
Update product | Admin |
DELETE |
/api/products/:id |
Delete product | Admin |
| Method | Endpoint | Description | Access |
|---|---|---|---|
GET |
/api/orders |
Get all orders (Admin) | Admin |
POST |
/api/orders |
Create a new order | Authenticated User |
GET |
/api/orders/:id |
Get order details | Authenticated User |
PUT |
/api/orders/:id |
Update order status | Admin |
| Method | Endpoint | Description | Access |
|---|---|---|---|
GET |
/api/admin/dashboard |
Get summary stats (users, sales, orders) | Admin |
GET |
/api/admin/users |
Get all registered users | Admin |
PUT |
/api/admin/users/:id/role |
Update user role | Admin |
Create a .env file in your root directory:
# PostgreSQL
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=yourpassword
DB_NAME=gocommerce
# JWT
JWT_SECRET=your_jwt_secret_key
JWT_EXPIRE_HOURS=24
# Server
PORT=8080