Skip to content

About

e-commerce template with Echo framework for Go

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

24 Commits

Folders and files

Repository files navigation

E-Commerce Basic Go (Echo)

A lightweight, modular e-commerce template built on the Echo web framework.

Go Coverage
License


Table of Contents


Overview

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

Features

  • 🔐 User Authentication
    • Registration, login, bcrypt password hashing
    • Cookie-based sessions & CSRF protection via Echo middleware
  • 🎨 Dynamic Templating
    • Server-side rendering with Go’s text/template and Echo’s renderer interface
    • Layouts, partials, and DRY templates
  • 🚀 Modular Architecture
    • internal/handler, service, repository, model, session, view
    • Interfaces & dependency injection for easy testing
  • ⚙️ Environment Configuration
    • .env support via godotenv
    • Single source of truth for DB, server & session settings
  • 🗄️ PostgreSQL Integration
    • Raw SQL migrations & seeds in migrations/
    • Connection pooling & error handling
  • 🌐 Static Asset Middleware
    • Serve images via Echo’s Static middleware
  • 🛡️ Middleware Stack
    • logging, panic recovery, authentication guards
  • ✅ Documentation
    • Detailed README & contribution guide

Prerequisites

  • Go ≥ 1.21
  • PostgreSQL ≥ 12
  • Make
  • Git

Configuration

  1. Copy and rename the example file:

    cp .env.example .env
  2. 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

Installation

  1. Clone the repo

    git clone https://github.com/nawwardiab/echo-go-template.git
    cd echo-go-template
  2. Install dependencies

    go mod download

Makefile Commands

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

Database Setup

Use the Makefile to manage migrations:

# Apply all migrations
make migrate-up

# Roll back the last migration
make migrate-down

Migration files live under migrations/ and follow a numeric prefix for ordering.


Usage

  • Run in development

    make run
  • Build a production binary

    make compile
    ./echo-server
  • Server listens on http://<SERVER_HOST>:<SERVER_PORT> by default.


API Reference

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

Contributing

  1. Fork the repository

  2. Create a feature branch:

    git checkout -b feature/awesome
  3. Commit your changes:

    git commit -m "feat: add awesome feature"
  4. Push to your branch and open a PR

Please follow:

  • Branch naming: feature/…, fix/…, chore/…
  • Code style: run gofmt and golint
  • Commit messages: Conventional Commits format

Roadmap

  • Docker & Docker Compose support
  • Payment gateway integration (Stripe / PayPal)
  • React/TypeScript frontend example
  • GraphQL API layer
  • OAuth social logins

License

This project is licensed under the MIT License. See LICENSE for details.


Contact

👤 Nawwar Diab

About

e-commerce template with Echo framework for Go

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages