Gecho-starter - A starter/boilerplate for Golang Echo API

gecho-starter

gecho-starter is a boilerplate for writing services in Golang quicker out the gates.

Foreword

This is my first attempt to write non-trivial code in this architecture style in Golang, so feedback is both greatly welcomed and desired.

The architecture used for this boilerplate is more or less derived from Clean Architecture and similar patterns such as Onion Architecture, and Hexagonal Architecture but is not strictly following any one pattern.

It attempts to strike a balance between being just wet enough to bring seperation but DRY enough to not make you catch a cold.

Architecture & Structure

In keeping with Clean Architecture, there are four layers

  1. External Interfaces (/http via Echo, /repository)
  2. Controllers (/http/controller)
  3. Use Cases (/interactor)
  4. Entities (/entity)

If you get Clean Architecture, this pattern should be pretty similar and easy to follow. Things like like inward dependencies only (layers can reach can reach in but never out) all hold true.

Various notes on implementation:

  • Entities, or the domain, are just structs. They describe our data in it's pure form and how we interact with it in Golang.
    • Interactors should be using entities, keeping it interface agnostic.
    • Repositories should be using entities too for actual data. Control entities needed such as limit or cursot are just implemented as parameters on the function.
  • Interactors are responsible for validation of data and proper default setting in addition to the logic.
  • Controllers are thin. In our case they just convert data to/from the interface.
  • Echo is our "http" interface in this example, which has a main.go file for running/starting that interface.
  • Error handling is centralized at the interface level so errors can be customized to the specific interface. This means everything should return both value and error and bubble up on error.

Running It

If you would like to run it make sure to populate a .env file with your database settings, reference .template_env for the naming.

To run the HTTP interface (Echo):

go run http/main.go

To run the unit tests with coverage:

go test -v ./... -race -covermode=atomic -coverprofile=coverage.out

Special Thanks

Special thanks to the "dev" community (ya'll know who you are) for helping me understand many of these concepts and providing feedback.

Owner
Jesse Pham
Full Stack Developer, Solutions Architect (AWS/GCP Pro) based in Tokyo Metropolitan Area. English/日本語OK. Very much still a learner.
Jesse Pham
Similar Resources

Hackpack-go: A starter pack for hacking in go

hackpack-go This repository is a starter pack for hacking in go Slides https://d

Apr 14, 2022

A microservice gateway developed based on golang.With a variety of plug-ins which can be expanded by itself, plug and play. what's more,it can quickly help enterprises manage API services and improve the stability and security of API services.

A microservice gateway developed based on golang.With a variety of plug-ins which can be expanded by itself, plug and play. what's more,it can quickly help enterprises manage API services and improve the stability and security of API services.

Goku API gateway is a microservice gateway developed based on golang. It can achieve the purposes of high-performance HTTP API forwarding, multi tenant management, API access control, etc. it has a powerful custom plug-in system, which can be expanded by itself, and can quickly help enterprises manage API services and improve the stability and security of API services.

Dec 29, 2022

Golang client for Ethereum and Flashbots JSON-RPC API calls.

Flashbots RPC client Fork of ethrpc with additional Flashbots RPC methods: FlashbotsGetUserStats FlashbotsCallBundle FlashbotsSendBundle FlashbotsSimu

Jan 5, 2023

Make Endpoint API using Golang, Mux Library, MySQL, and Redis

EndPoint API (Create and Read) I'm Using Golang, Mux Library, MySQL, and Redis Golang Documentation : https://go.dev/doc/ Golang Instalation : https:/

Dec 12, 2021

A simple HTTP/HTTPS API Gateway in Golang.

A simple HTTP/HTTPS API Gateway in Golang.

mice A simple API Gateway in Golang. Installation: Using go install: First install Go, if not already there Set GOPATH and GOBIN if not already set as

May 19, 2022

HTTP API Gateway

HTTP API Gateway

Manba/简体中文 Manba is a restful API gateway based on HTTP, which can be used as a unified API access layer. Tutorial A very detailed tutorial for beginn

Dec 29, 2022

This is a shopping basket workshop that shows how to use KrakenD API Gateway.

This is a shopping basket workshop that shows how to use KrakenD API Gateway.

Go Restful Microservices and KrakenD API Gateway Workshop This is a shopping basket workshop that shows how to use KrakenD API Gateway. Consist of 5 m

Jan 3, 2023

以 `Go` 语言,采用 斗鱼 微服务框架Jupiter 实现后端 API 开发

以 `Go` 语言,采用 斗鱼 微服务框架Jupiter 实现后端 API 开发

lightning-go 环境依赖 版本依赖 Go 1.14+ MySQL 5.7+ Redis 3.2+ 模块介绍 多云云主机生命周期管理 阿里云 腾讯云 华为云 亚马逊 消息中心 任务调度 触发Dag任务 查询Dag详情 查看任务日志 定时任务 项目目录结构

Jun 18, 2022

Test your API gateway routed lambdas locally and in CI

Test your API gateway routed lambdas locally and in CI

Lambo Test API Gateway wrapped lambda functions locally. Lambo can also be used to test API GW lambdas in CI without needing docker-in-docker. It will

Jun 22, 2022
CRUD API server of Clean Architecture with Go(Echo), Gorm, MySQL, Docker and Swagger
CRUD API server of Clean Architecture with Go(Echo), Gorm, MySQL, Docker and Swagger

CRUD API Server of Clean Architecture Go(echo) gorm mysql docker swagger build docker-compose up -d --build API Postman and Fiddler is recommended to

May 30, 2021
It's a lean boilerplate to start developing a microservice in Go.

Go microservice starter It's a lean boilerplate to start developing a microservice in Go. Features Gin server Godotenv to load environment variables M

Dec 27, 2021
MadeiraMadeira boilerplate project to build scalable, testable and high performance Go microservices.

MadeiraMadeira boilerplate project to build scalable, testable and high performance Go microservices.

Sep 21, 2022
Starter code for writing web services in Go

Ultimate Service Copyright 2018, 2019, 2020, 2021, Ardan Labs [email protected] Ultimate Service 2.0 Video If you are watching the Ultimate Service v

Dec 30, 2022
An opinionated Microservice starter in Go

Go Microservice Starter An opinionated Microservice starter in Go Usage Checkout the code. TLDR; Start the service: docker build -t go-microservice-st

Oct 25, 2021
Kyoto starter project
Kyoto starter project

kyoto starter Quick Start project setup What's included kyoto kyoto uikit tailwindcss How to use Clone project with git clone https://github.com/yurii

Apr 10, 2022
A starter repo for VS Code, Gitpod, etc for Go.

go-starter After using this template: Replace github.com/mattwelke/go-starter in go.mod after using this template. Replace go-starter in .gitignore wi

Nov 26, 2021
Astro Starter Kit: Docs Site

Astro Starter Kit: Docs Site npm init astro -- --template docs Features ✅ Full Markdown support ✅ Responsive mobile-friendly design ✅ Sidebar navigat

Apr 10, 2022
GCP Cloud Functions ready to Go starter with hot reload 🔥

GCP Cloud Functions - Go Starter Features: funcFramework already set up - ready for local development and testing. Hot Reload ready-to-go thanks to th

Dec 16, 2021
The starter code for Module 3: Surfstore

Surfstore This is the starter code for Module 3: Surfstore. Before you get start

Feb 13, 2022