shorty

module
v0.0.0-...-cc299b8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2021 License: MIT

README

Go Reference Go Report Card

Description

Shorty is a practice project showcasing a simple link shortener built on top of Redis. It is intended to be run in Docker. Application data is stored in /data volume of Redis container.

Dependencies

  • go 1.16
  • docker

API

POST / -d '<original URL>'

Saves an original URL passed via POST request body into Redis, generates and returns a unique short alias for the original URL. If this URL is already present in Redis, simply returns an existing alias for it.

GET /<short_alias>

Retrieves original full URL saved into Redis earlier by its <short_alias>

Example

make run
curl localhost:8080 -d 'google.com'

localhost:8080/b

curl localhost:8080/b

google.com

curl localhost:8080 -d 'golang.org'

localhost:8080/c

curl localhost:8080/c

golang.org

curl localhost:8080 -d 'google.com'

localhost:8080/b

Environment variables

All env variables can be set in the .env file (example provided in the repository).

  • HOST_PORT application port;
  • CONTAINER_PORT docker container port;
  • REDIS_URL URL used for connection to Redis;
  • DB_NUM Redis db number where the data is stored.

Make commands

make run

Builds shorty via docker-compose.yml and runs it in Docker.

make down

Stops shorty containers running in Docker and removes all related images.

make clear

Same as make down but also removes redis-data volume where the application data is stored.

Metrics

Basic metrics are provided by Prometheus and available via /metrics handler on the :8081 port.

Directories

Path Synopsis
Package handlers is a generated GoMock package.
Package handlers is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL