url-shortener

module
v0.0.0-...-3dea803 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: Apache-2.0

README

url-shortener

This service reduces long links from sites on the Internet. If you like the project or use it for any purpose, don't hesitate to give it a star on GitHub!

Overview

The entry point to the code is in cmd/url-shortener/url-shortener.go. The service has the following HTTP handlers:

  • /shorten - use the POST method and x-www-form-urlencoded parameters url with a URL for shortening. Returns base62 code of the URL.
  • /{code} - use GET method and substitute {code} with actual URL code received from the service like udXWFB. Returns the full URL from the code.
  • /readiness - check if the database is ready and, if not, will return a 500 status.
  • /liveness - return simple status info if the service is alive.

Prerequisites

Installation

  1. Clone this repository in the current directory:

    git clone https://github.com/illyasch/url-shortener
    
  2. Build Docker images:

    make image
    
  3. Migrate and seed the database (uses Docker):

    make seed
    
  4. Start the local development environment (uses Docker):

    make up
    

    At this point, you should have the url-shortener service running. To confirm the state of the running Docker container, run

    $ docker ps
    

How to

Run unit tests

from the docker container

make test
Run manual tests

Shorten a URL

$ curl -i --data-urlencode "url=http://www.cnn.com" http://localhost:3000/shorten
HTTP/1.1 200 OK
Content-Type: application/json
Date: Sun, 12 Jun 2022 16:05:58 GMT
Content-Length: 17

{"code":"vdXWFB"}

Get a shortened URL with the code.

$ curl -i http://localhost:3000/vdXWFB
HTTP/1.1 200 OK
Content-Type: application/json
Date: Sun, 12 Jun 2022 16:07:48 GMT
Content-Length: 28

{"url":"http://www.cnn.com"}

Directories

Path Synopsis
cmd
tooling/admin
This program performs administrative tasks for the url-shortener service.
This program performs administrative tasks for the url-shortener service.
url-shortener
Grüezi! This service reduces long links from sites on the Internet.
Grüezi! This service reduces long links from sites on the Internet.
url-shortener/handlers
Package handlers manages the different versions of the API.
Package handlers manages the different versions of the API.
pkg
business/shortener
Package shortener implements saving/extracting URL to/from database and encoding/decoding URL database id to BASE62 formatted string.
Package shortener implements saving/extracting URL to/from database and encoding/decoding URL database id to BASE62 formatted string.
data/database
Package database provides support for access the database.
Package database provides support for access the database.
data/database/dbschema
Package dbschema contains the database schema, migrations and seeding data.
Package dbschema contains the database schema, migrations and seeding data.
sys/logger
Package logger provides a convenience function to constructing a logger for use.
Package logger provides a convenience function to constructing a logger for use.

Jump to

Keyboard shortcuts

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