Clean Architecture / Hexagonal Architecture in Go
✅
Install
First clone the repo
git clone https://github.com/prinick96/hex-arch-go.git
- Just create a database
- Upload the schema on your DB
/db/schema.sql
- Change the enverioment variables located in .env.development
DB_ENGINE = "postgres or mysql"
DB_HOST = "host"
DB_PORT = 1234
DB_DATABASE = "db name"
DB_USERNAME = "user name"
DB_PASSWORD = "your secret password"
# For cockroach
DB_OPTIONS = "--cluster=cockroach-cluser-id"
# For postgres
DB_OPTIONS = "sslmode=disable timezone=UTC connect_timeout=5"
# For mysql
DB_OPTIONS = ""
✅
Run
If you want run in local, simply
go get
go run main.go
If you want run with Docker, simply
make docker-up
If you want run with Heroku local, simply
# For Linux/MacOS
make heroku-run
# For Windows
heroku-run-win
# For windows use
web: bin\hex-arch-go.exe
# web: bin/hex-arch-go
And now you can run Heroku local for Windows
✅
Test
For unit tests, simply
make unit-test
make integration-test
Or both of them
make test
🌳
Understanding the folder structure
.
├── /.github/workflows # Github Actions!
├── /cmd # Start the application with server and database
├── /core # The CORE of hexagonal architecture: infrastructure, application and domain
│ ├── /application # Handlers and the entry point of data
│ ├── /entities # The entities what conform the domain
│ └── /infrastructure # Gateways for the domain logic and Storage/Repository for the implementation of database
├── /db # Simply the schema of DB for you first run
├── /env # .env loader
├── /internal # Elemental logic common for all the system
│ ├── /database # Connection with database implemented
│ └── /helpers # Reusable functions around the app, like a UUID generation
│ └── tests # Unit tests for helpers
└── /server # The server listener and endpoints of API REST