A lightweight, modular e-commerce template built on the Echo web framework.
e-commerce-basic-go-echo is a starter template for building a full-featured online store using Go and the Echo framework. It demonstrates idiomatic Go, Echo’s powerful routing & middleware, and a modular architecture designed for production readiness.
Use this project to:
- Rapidly prototype secure user workflows
- Manage products, carts, and sessions
- Learn best practices for building backend services with minimal dependencies
- 🔐 User Authentication
- Registration, login, bcrypt password hashing
- Cookie-based sessions & CSRF protection via Echo middleware
- 🎨 Dynamic Templating
- Server-side rendering with Go’s
text/templateand Echo’s renderer interface - Layouts, partials, and DRY templates
- Server-side rendering with Go’s
- 🚀 Modular Architecture
internal/handler,service,repository,model,session,view- Interfaces & dependency injection for easy testing
- ⚙️ Environment Configuration
.envsupport viagodotenv- Single source of truth for DB, server & session settings
- 🗄️ PostgreSQL Integration
- Raw SQL migrations & seeds in
migrations/ - Connection pooling & error handling
- Raw SQL migrations & seeds in
- 🌐 Static Asset Middleware
- Serve images via Echo’s
Staticmiddleware
- Serve images via Echo’s
- 🛡️ Middleware Stack
- logging, panic recovery, authentication guards
- ✅ Documentation
- Detailed README & contribution guide
- Go ≥ 1.21
- PostgreSQL ≥ 12
- Make
- Git
-
Copy and rename the example file:
cp .env.example .env
-
Fill in your environment variables in
.env:DB_HOST=localhost DB_PORT=5432 DB_USER=your_user DB_PWD=your_password DB_NAME=shop DB_URL=postgres://${DB_USER}:${DB_PWD}@${DB_HOST}:${DB_PORT}/${DB_NAME} STATIC_DIR=./static SESSION_KEY=supersecretkey SERVER_HOST=0.0.0.0 SERVER_PORT=8080
-
Clone the repo
git clone https://github.com/nawwardiab/echo-go-template.git cd echo-go-template -
Install dependencies
go mod download
All commands assume your .env is properly configured.
| Command | Description |
|---|---|
make compile |
Compile binaries (go build) |
make run |
Compile & run the app (go run main.go) |
make migrate-up |
Apply all DB migrations |
make migrate-down |
Roll back last DB migration |
make clean |
Remove binary (rm -f echo-server) |
make reload |
Clean, compile & run |
Use the Makefile to manage migrations:
# Apply all migrations
make migrate-up
# Roll back the last migration
make migrate-downMigration files live under migrations/ and follow a numeric prefix for ordering.
-
Run in development
make run
-
Build a production binary
make compile ./echo-server
-
Server listens on
http://<SERVER_HOST>:<SERVER_PORT>by default.
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Home page |
| GET | /products |
List all products |
| GET | /products/:id |
View single product |
| POST | /register |
Create a new user account |
| POST | /login |
Authenticate & start session |
| GET | /cart |
View current user's cart |
| POST | /cart/add |
Add item to cart |
| POST | /cart/remove |
Remove item from cart |
-
Fork the repository
-
Create a feature branch:
git checkout -b feature/awesome
-
Commit your changes:
git commit -m "feat: add awesome feature" -
Push to your branch and open a PR
Please follow:
- Branch naming:
feature/…,fix/…,chore/… - Code style: run
gofmtandgolint - Commit messages: Conventional Commits format
- Docker & Docker Compose support
- Payment gateway integration (Stripe / PayPal)
- React/TypeScript frontend example
- GraphQL API layer
- OAuth social logins
This project is licensed under the MIT License. See LICENSE for details.
👤 Nawwar Diab
- LinkedIn: https://www.linkedin.com/in/nawwardiab