Requires before start:
- DB Diagram https://dbdiagram.io/
Describe for all files and directories structure using in this project.
.
├── api
├── constants
├── internal # Internal package, only share to internal project
│ ├── helper # Contain Helper functions
│ ├── message # The error/response messages
│ ├── service # internal - background service
├── migrations # Contain SQL scripts
├── migrations_test # Contain SQL scripts include mock-data for testing
├── model
├── routes
├── scripts # All bashscript to help to run on production
├── .env.sample # Global config for db and docker-compose
├── Dockerfile
├── go.mod
├── go.sum
├── main.go
├── README.md
└── ...
- One
api
package can have many handlers. - One
handler
contains controller - model - repository - route.- Controller will handle request, response and validate.
- Model contains all structs/interface and mapping.
- Repository handles the request to get data from database.
- Route contains config for routes of handler.
api
├── controller_base.go # The controller inside handler should inherit this
├── repository_base.go # The repository inside handler should inherit this
├── handler
│ ├── controller.go
│ ├── model.go
│ ├── repository.go
│ ├── route.go # Config routes for the handler
└── ...
NOTE: clone this project and put follow this path $GOPATH/src/github.com/trinhquocviet/go-echo-skeleton
, all codebase should place inside this folder.
01 - Run the command to create .env
file
cp .env.sample .env
02 - Run the command to install the missing libs
go install
03 - Start project
export $(grep -v '^#' .env | xargs) && go run main.go
01 - Run the command below to run the test
export $(grep -v '^#' .env | xargs) && go test ./... -count=1