Gohex is a CLI application that helps you create the initial files and folders to implement the hexagonal architecture in a microservice with Go.
It can be installed by running:
$ go install github.com/andresxlp/gohex@latest
- Create a folder where you are going to work and enter it:
$ mkdir myProyect && cd $_
- Execute gohex command:
$ gohex new myProyect
- Set necessary env's to run
SERVER_HOST
SERVER_PORT
If you develop in IntelliJ or Goland IDE set env in your build configuration
If you develop in VSCode create an .env file in your root folder and check the config.go file
This generator has basic structure like this
Folder Struct:
ROOT FOLDER
├─ cmd
│ └─ providers
├─ config
└─ internal
├─ app
├─ constants
├─ domain
│ ├─ dto
│ ├─ entity
│ └─ ports
└─ infra
├─ api
│ ├─ handler
│ ├─ middleware
│ └─ router
│ └─ groups
└─ resource
As main dependencies for the creation of the initial structure we use:
- echo -
High performance, extensible, minimalist Go web framework.
- dig -
A reflection based dependency injection toolkit for Go.
- envconfig -
Decoding of environment variables.
When Gohex successfully creates the initial structure, don't forget set the environment variables to run your Microservice locally
SERVER_HOST
: host for the serverSERVER_PORT:
port for the server