Skip to content

URL Shortener implemented in Go using Clean Architecture with Echo and Fiber as HTTP Adapters.

Notifications You must be signed in to change notification settings

lucasfrancaid/go-url-shortener

Repository files navigation

go-url-shortener

URL Shortener implemented using Go with Clean Architecture as architecture design to structure the codebase and some adapters to switch by initiliazing command.

Infrastructure

  • ✅ Environment settings with Viper
  • ✅ Docker Image
  • ✅ Docker Compose
  • ✅ Dependency Injection for Adapters using Factory Pattern
  • ✅ OpenAPI Documentation/Swagger with Swag
  • ⭕ CI&CD/Deploy

Web Adapters

Built-in:

External:

Repository Adapters

Built-in:

  • ✅ In Memory

External:

To Do

  • ⭕ Add tests for HTTP Adapters
  • ⭕ Add tests for Presenters

Setting up with Docker

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 to http/echo or http/standard. For example:
    server:
        build:
            context: ../.
            dockerfile: build/packages/Dockerfile
            args:
                - GO_VERSION=1.20
                - ADAPTER=http/echo # Change here
            network: "host"

Running with Docker

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

Running with Docker Compose

To setup the server with docker compose you need run:

docker compose -f deploy/docker-compose.yml up --build -d server

Swagger

After start the server, you can access the Swagger Documentation.

Makefile Commands

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

Initial System Design

System Design Image

About

URL Shortener implemented in Go using Clean Architecture with Echo and Fiber as HTTP Adapters.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages