+
Skip to content

FranzBranntvino/urlsGoShort

Repository files navigation

URLs GO Short

Task

Create and document a small web service exposing URL shortening functions. One should be able to create, read, and delete shortened URLs. The API functions will be exposed under the /api path while accessing a shortened URL at the root level will cause redirection to the shortened URL.

Rules of the game

  • Code in Golang (unless differently agreed)
  • It's ok to forget about permissions (everyone can do anything) for the sake of the exercise.
  • Documentation will be publicly exposed via a specific service URL.
  • Code will be tested to a reasonable extent
  • You're free to choose any storage mechanism you wish

We expect to be able to run the application locally just following the project README documentation. Do not assume the host running your service will meet any requirement (no storage engine is pre-installed).

Bonus

  • Implement a counter of the shortened URL redirects
  • Add an API endpoint to read shortened URL redirects count

Philosophy of Planning and Design

  • Assume you always start wrong (being ill informed on the beginning of any project is the only thing that is right), makes starting assumptions always questionable
  • Assume there will always be change (make it easy to be able to change things and revise decisions taken in the beginning)

How it works

In short it has as a prerequisite:

Start up the Services

# build and run services:
docker-compose up --build
# stop and remove services:
docker-compose down

or for already existing containers

# start services:
docker-compose start
# stop services:
docker-compose stop

Try out the Demo

Visit http://localhost:8080 for a Demo-Frontend.

The statistics for a short-link can be requested via http://localhost:8080/shortUrlStats/"put_url-Code_here"

Look at the godoc Documentation

The documentation for the Go-App is available under http://localhost:6060/pkg/urlShortener/.

Specifically for the REST-API follow the link http://localhost:6060/pkg/urlShortener/urlHandler/#pkg-constants.

Dev-Setup

Prerequisite:

NOTE: It might be that in the current Dev-Setup some of the Tests are failing if the DB-Service are not running, hence the DB-client is unable to connect to the DB.

Areas for Improvement

  • Some Status Codes of the response are not used right: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes and https://cheatography.com/jp153/cheat-sheets/http-status-codes-golang/

  • Improve on REST API, e.g. Naming, Documentation, Functionality, GET, POST and DELETE usage, return JSON

  • Separate concerns for Unit and Integration tests: provide mocks and stubs for the unit tests to work sufficiently and independent from other modules (DB Service)

  • Default Handling for undefined routes

  • Implement graceful stopping of http-Server

  • Implement graceful stopping of DB-client

  • Build in scalability for the services

  • Make Mega-Links work: e.g. long (>2000 chars) full version of https://godbolt.org/z/9TeK9hYh9

    • reference: https://bitly.com/ does not work with it either and it is supposing this seems to be an invalid URL
  • Handling of local links (e.g. local files), despite they lead to security violations: file:///home/vagrant/urlsGoShort/.devcontainer/README.md

    • Second besides the formatting issue is, that this is a Security issue in some Browsers: Security Error: Content at http://localhost:8080/ may not load or link to file:///home/vagrant/urlsGoShort/.devcontainer/README.md.
    • reference: https://bitly.com/ does not work with it either and it is supposing this seems to be an invalid URL
  • Improve on Frontend formatting e.g. representation of very long links, Error Responses/Handling/Messaging

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载