This is a template for Go project with clean architecture.
go-clean-template
├── cmd
│ ├── httpserver
│ └── migrate
├── entity/domain/model
├── handler //as controller
│ └── httpserver
│ ├── middleware
│ ├── model
│ ├── options.go
│ ├── server.go
│ └── *_handler.go //handle request to client
├── infras
│ ├── paymentsvc //call API to payment service provider
│ ├── notification //push noti
│ └── postgrestore
│ ├── schema
│ ├── postgresql.go //contains actions to connect DB
│ └── *_repo.go //implement repository interfaces
├── migrations //contains migration files
├── pkg // contains common packages
│ ├── apperror
│ ├── config
│ ├── constant
│ ├── logger
│ ├── sentry
│ └── validation
├── tools
│ ├── compose
│ └── pre-commit
└── usecase
├── mocks //contains mock files used for unit testing
├── interface.go //contains all interfaces
└── ... //specific usecases
-
Copy file
.env.example
and rename to.env
-
Update env vars to fit your local
-
Start local services
make local-db
-
Run the server
make run
-
Unit test
make test
-
Generate Mock
make mock
make lint
sql-migrate new -env="development" Init-database
- Result:
Created migration migrations/20240704092049-Init-database.sql
Then run migration:
make db/migrate