Clean Architecture with Golang with Dependency Injection
To install all the packages and run the linter in git pre-commit hook; Run
Make lint-setup
⚓️ Add argument
p=host
aftermake
if you want to run the migration runner from the host environment instead of docker environment. example;make p=host migrate-up
If you are not using docker; ensure that sql-migrate is installed to use migration from the host environment. To install sql-migrate:
go get -v github.com/rubenv/sql-migrate/...
Migration commands available
Command | Desc |
---|---|
make migrate-status |
Show migration status |
make migrate-up |
Migrates the database to the most recent version available |
make migrate-down |
Undo a database migration |
make redo |
Reapply the last migration |
make create |
Create new migration file |
- Update database env variables with credentials defined in
docker-compose.yml
- Start server using command
docker-compose up -d
orsudo docker-compose up -d
if permission issuesAssumes: Docker is already installed in the machine.
- Run
go run main.go app:serve
to run app server. - There are other commands available as well. You can run
go run main.go -help
to know about other commands available.
The framework comes with unit and integration testing support out of the box. You can check examples written in tests directory.
To run the test just run: go test ./... -v
go test ./... -v -coverprofile cover.txt -coverpkg=./...
go tool cover -html=cover.txt -o index.html
Browse to http://localhost:${SWAGGER_PORT}
- You can see all the documented endpoints in Swagger-UI from the API specification
- You can execute/test endpoint You can read the article to know more on this: https://medium.com/wesionary-team/swagger-ui-on-docker-for-testing-rest-apis-5b3d5fcdee7
Steps to Update Dependencies
go get -u
- Remove all the dependencies packages that has
// indirect
from the modules go mod tidy
Discovering available updates
List all of the modules that are dependencies of your current module, along with the latest version available for each:
$ go list -m -u all
Display the latest version available for a specific module:
$ go list -m -u example.com/theirmodule
Example:
$ go list -m -u cloud.google.com/go/firestore
cloud.google.com/go/firestore v1.2.0 [v1.6.1]
Getting a specific dependency version
To get a specific numbered version, append the module path with an @ sign followed by the version you want:
$ go get example.com/[email protected]
To get the latest version, append the module path with @latest:
$ go get example.com/theirmodule@latest
Synchronizing your code’s dependencies
$ go mod tidy