My go backend template. This is a go boiplerplate to quickly started the new project with golang and standard dependencies for local development pipeline.
Table of Contents
- Getting Started
- Prerequsition
- 👩⚕️ Pre-Commit
- Commit Lint
- Miscellaneous
- Set $GOPATH
- Hexagonal Architecture
- Architecture Components
- Core
- Domain
- Service
- Repository
- Dependency Injection
Design Structure สรุปเรื่อง GopherCon 2018: Kat Zien — How Do You Structure Your Go Apps
Features
- Hot-Reloader with Air.
- Pre-commit.
Please run $ make init
to initialize the basic needed command and dependencies for your local development. We built this command to install the stuff to make the industry stnadard good grade to local development.
Here is a standard development pipeline installed.
- go
- node
- pre-commit
You can reached pre-commit hooks and rules under .pre-commit-config.yaml
configuration file.
The commit lint is make more sense of good engineering should be. Essepcially, the commitlint
, in this template I've follow the convention here https://www.conventionalcommits.org/en/v1.0.0/
The $GOPATH environment variable lists places for Go to look for Go Workspaces.
https://go.dev/doc/gopath_code#GOPATH
Add this to your profile. If you use zsh please also update .zshrc
export GOPATH="$HOME/go"
PATH="$GOPATH/bin:$PATH"
then source .zshrc
for reload the the environment. You can check you GOPATH by go env GOPATH
This golang project adopt the hexagonal architecture to grouping the code by domain and context of business problems.
Everything surrounded the core
this layer contains the concrete core business logics.
The core could be viewed as a “box” (represented as a hexagon) capable of resolve all the business logic independently.
The domain entity it contains the go struct definition of each entity that is part of the domain problem and can be used across the application.
Seperate of concern For example, this layer should not be known how the data keeps its, or how the caching store in the redis.
Port is the interfaces are the ports that external actors will plug their adapters into to drive the application.
Adapter is the implementation of the ports
Service is through which the client will interact with actual business logic/domain objects. The client can be rest handlers, test agents, etc.
The repository interface allows us to connect to multiple data sources.
Outside concerns, such as repositories and user interfaces, use the adapters to plug into the business domain services.
References