This project was based on an article from a blog but changes were made to the structure, tests and libraries. Also try to implement DDD in the project, this would be a simple implementation of DDD for Golang
The following technologies were used in this project:
- Golang 1.15
- go-chi
- go-chi/cors
- pq
- aws-sdk-go
- go-redis
- uuid
- jwt-go
- godotenv
- checkmail
- yalm
- errors
- objx
- crypto
- testify
- go-cmp
- mockery
- go-sqlmock
- miniredis
- PostgreSQL
- golang-migrate
- Golang 14+
- Docker
- Docker Compose
- go-swagger
- It is necessary to have this plugin installed, this is the installation process:
go get -u github.com/go-swagger/go-swagger go install ./cmd/swagger
This is an automatic mock generator using mockery, the first thing we must do is go to the path of the file that we want to autogenerate:
Download the library
go get -u github.com/vektra/mockery
We enter the route where you are
cd path
After entering the route we must execute the following command, Repository this is name the interface
mockery -name Repository
This is the command that runs the swagger autogenerated documentation
- the document can be generated in the following formats in:
- yalm
- json
swagger generate spec -o ./swagger.json --scan-models
This is the command to start the server with the documentation
- You can generate the documentation in swagger and redoc that is changed in the variable
-F=
swagger serve -F=redoc swagger.json
Raise the server without automatic start, with specific port and path
swagger serve -F=redoc --host=0.0.0.0 --port=8082 --no-open swagger.json
You can get more information in the Swagger documentation:
localhost:8082/docs
These are the commands to run the unit and integration tests of the project
This is the command to run the white box tests, and the test report command
go test -v -coverprofile=coverage.out -coverpkg=./domain/... ./test/...
go tool cover -html=coverage.out
This command gets the total coverage of the project
go tool cover -func coverage.out
This is the command to run the black box tests, and the test report command
go test -v -coverprofile=coverage_integration.out -coverpkg=./domain/... ./test/integration
go tool cover -html=coverage_integration.out
The command to run the handler tests, and the command to generate the report
go test -v -coverprofile=coverage.out -coverpkg=./domain/user/application ./test/handler/user
go tool cover -html=coverage.out
The command to run the handler tests, and the command to generate the report
go test -v -coverprofile=coverage.out -coverpkg=./domain/user/application/v1 ./test/handler/user/v1
go tool cover -html=coverage.out
The command to run the handler tests, and the command to generate the report
go test -v -coverprofile=coverage.out -coverpkg=./domain/food/application/v1 ./test/handler/food/v1
go tool cover -html=coverage.out
The command to run the handler tests, and the command to generate the report
go test -v -coverprofile=coverage.out -coverpkg=./domain/user/infrastructure/persistence ./test/repository/user
go tool cover -html=coverage.out
The command to run the handler tests, and the command to generate the report
go test -v -coverprofile=coverage.out -coverpkg=./domain/food/infrastructure/persistence ./test/repository/food
go tool cover -html=coverage.out
The command to run the handler tests, and the command to generate the report for these tests redis must be above
go test -v -coverprofile=coverage_integration.out -coverpkg=./domain/user/application/ ./test/integration
go tool cover -html=coverage_integration.out
The command to run the handler tests, and the command to generate the report for these tests redis must be above
go test -v -coverprofile=coverage_integration.out -coverpkg=./domain/user/application/v1/ ./test/integration
go tool cover -html=coverage_integration.out
The command to run the handler tests, and the command to generate the report for these tests redis must be above
go test -v -coverprofile=coverage_integration.out -coverpkg=./domain/food/application/v1/ ./test/integration
go tool cover -html=coverage_integration.out
First clone the repo then go to food-api folder. After that build your image and run by docker. Make sure you have docker in your machine.
git clone https://github.com/samuskitchen/food-api.git
cd food-api
docker-compose up -d --build
docker-compose down --remove-orphans --volumes
These are the commands to execute and in the following order
cd installers/
This command starts the app
./installFood-Api.sh
This command starts the swagger server
./swaggerFood-Api.sh &
disown