[Go clean architecture]
boilerplate modification from https://github.com/cmparrela/go-clean-architecture
Examples of types of communication;
- API
- CLI
Examples of data persistence;
- Mysql
- Mongo
- In memory
- redis
Example:
- rest api
- Dockerfile with multi stage build (for prod/staging)
- DockerfileDev (for local environment)
- Docker-compose
- swagger for doc
- middleware auth jwt
- migration
- unit testing with mock and table test
- concurrency with goroutines by implementing mutex and locking rows to avoid race conditions (on checkout api)
- worker queue using asynq library
go install github.com/swaggo/swag/cmd/swag@latest
go install -tags 'mysql' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
$ docker-compose up -d
$ make migration-up
$ make migration-down
$ make migration
#type your migration name example: create_create_table_users
$ ./entrypoint.sh
#install openssl on your OS and run command below
$ make generate-jwt-secret
#copy the secret key and then create new env called JWT_SECRET in .env file:
$ make generate-swag
$ make test-cov
#entering go app Docker container
$ docker exec -it go-app /bin/sh
#create user
$ go run cmd/main.go user create -n=teste -e=teste@gmail.com
#update user
$ go run cmd/main.go user update -n=teste -e=teste@gmail.com -i=9cc26bf0-1272-45c8-93c5-1d83cfe82033
API Documentation was created with swagger and is available at http://localhost:5001/docs
Available at http://localhost:5001