Skip to content

gnaydenova/url-shortener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

A simple URL Shortener service that shortens, stores, and resolves URLs. It uses base62 encoding with a random number to generate the short url. The random number is between 1-916132833 which guarantees a short url with max length of 5 characters (number of permutations with max 5 chars: 625 = 916132832).

Prerequisites

Check go version:

go version

Check that the service is running (for MacOS, using brew):

brew services list
Name              Status  
mongodb-community started

Run

Start the service with:

go run cmd/main.go

To run all tests use:

go test ./... -v

Usage

Get short url:

curl 'http://localhost:8090/' -H 'Content-Type: text/plain;charset=UTF-8' --data-raw 'https://someverylongdomainnamehere.com/some/very/very/long/path/here?foo=bar'

Example result:

P8gCt

Going to http://localhost:8090/{shortUrl} will result in a redirect to the original url.

Curl:

curl 'http://localhost:8090/P8gCt'

Example result:

<a href="https://someverylongdomainnamehere.com/some/very/very/long/path/here?foo=bar">Moved Permanently</a>.

About

Simple url shortener

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages