Skip to content

kiryu2k/shorty

Repository files navigation

Shorty

Shorty is a simple URL shortener written in Go using PostgreSQL as storage. The project can be deployed locally and in Docker containers. The service is implemented in such a way that only one alias can be assigned to one URL. This means that before trying to shorten URL that already has an alias, a new alias will not be generated. Instead, an existing one will be returned to the user. The alias is generated as follows:

  1. A hash value is generated using the SHA256 algorithm for the entered URL.
  2. Derive a big integer number from the hash value bytes generated during the hasing.
  3. Binary-to-text encoding is then applied. Base58 is used as standard encoding.

Usage

Create a short URL:

curl -X POST -d '{"url":"https://github.com/kiryu-dev/shorty"}' localhost:8080/url

Redirect from a short URL:

curl -IX GET localhost:8080/url/<existing_alias>

Tech Stack

  1. Router: chi.
  2. DB and stuff: PostgreSQL, migrate cli util, database/sql golang package and pq driver.
  3. Test: golang test package and testify lib for unit-testing.
  4. Configuration: cleanenv and godotenv.
  5. Other: validator, base58 algorithm.

About

Simple URL shortener

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published