URL Shortener implemented using Go with Clean Architecture as architecture design to structure the codebase and some adapters to switch by initiliazing command.
- ✅ Environment settings with Viper
- ✅ Docker Image
- ✅ Docker Compose
- ✅ Dependency Injection for Adapters using Factory Pattern
- ✅ OpenAPI Documentation/Swagger with Swag
- ⭕ CI&CD/Deploy
Built-in:
- ✅ net/http 🔗
External:
Built-in:
- ✅ In Memory
External:
- ⭕ Add tests for HTTP Adapters
- ⭕ Add tests for Presenters
This project was built to easily change vendors, so you can configure it according your desire.
For Dockerfile and Docker Compose, by default the HTTP Adapter configured is Fiber, but you can easily change it on:
- Dockerfile: When build the docker image you need to pass
--build-arg="ADAPTER=http/echo"
or--build-arg="ADAPTER=http/stantard"
as argument. For example:docker build --build-arg="ADAPTER=http/echo" -f build/packages/Dockerfile -t url-shortener .
- Docker Compose: You need change in docker-compose.yml file the
services.server.build.args.ADAPTER
configuration tohttp/echo
orhttp/standard
. For example:server: build: context: ../. dockerfile: build/packages/Dockerfile args: - GO_VERSION=1.20 - ADAPTER=http/echo # Change here network: "host"
To setup the server with docker you need build the image first:
docker build --build-arg="ADAPTER=http/fiber" -f build/packages/Dockerfile -t url-shortener .
Then, run a new container with image built:
docker run --name url-shortener -v "$PWD":/usr/app/ -p 3000:3000 -d url-shortener
To setup the server with docker compose you need run:
docker compose -f deploy/docker-compose.yml up --build -d server
After start the server, you can access the Swagger Documentation.
Run server setting ENV and ADAPTER:
make http env=<dev|qa|prod> adapter=<echo|fiber|standard>
Run tests with arguments:
make test args='-v'
Run tests coverage:
make coverage
Generate swagger documentation with swaggo/swag:
make swagger bin=/home/go/bin/ # bin is optional, should be used if you have not installed swag global