GithubHelp home page GithubHelp logo

url-shortener's Introduction

Go Report Card Go

URL Shortener Service

URL Shortener service in Go. Functionality:

  • Create/Describe/Delete shortened urls
  • Redirect shortened urls to Original
  • Check statistic: redirections count, lastRedirectTime

API Documentation

SwaggerHub
https://app.swaggerhub.com/apis/vrazdalovschi/url-shortener/0.1.0-oas3 

API docs are available by swagger (api/swagger.yaml). Just deploy using docker-compose:

Api Definition

http://localhost:8080/swaggerui/swagger.yaml

SwaggerUi

http://localhost:8080/swagger/index.html

Run

Run with Docker (deployments folder)

cd deployments
docker-compose up -d --build

Assumptions and expected environment

Project is developed in GO 1.14 an instance with go 1.14 is expected

Configuration options

Available using first flags if not set then env variable

HTTP_ADDR    -  Endpoint port (default value :8080)

Postgres related

DB_HOST       - Database Host. Default: localhost
DB_PORT       - Database Port. Default: 5432
DB_USER       - Database User. Default: url-shortener
DB_PASSWORD   - Database Password. Default: root
DB_NAME       - Database Name. Default: shortener

Storage

Postgres is chosen for storage purposes.

Schema definition

Tables are auto created on starting the project.

Urls table.

CREATE TABLE IF NOT EXISTS url 
  ( 
     shortenedid    VARCHAR NOT NULL UNIQUE, 
     originalurl    VARCHAR NOT NULL, 
     apikey         VARCHAR NOT NULL, 
     creationtime   TIMESTAMP NOT NULL, 
     expirationdate TIMESTAMP NOT NULL 
  );

Statistics table.

CREATE TABLE IF NOT EXISTS stats 
  ( 
     shortenedid VARCHAR NOT NULL UNIQUE, 
     redirects   INTEGER DEFAULT 0, 
     visitdate   TIMESTAMP 
  ); 

Known issues

  • Test Coverage
  • Better error handling
  • Distributed caching
  • SQL Schema migration

Instrumentation

Prometheus metrics:

  • System load
  • Latency summary per each api call (success/error)
  • Counter for each api call (success/error)
http://localhost:8080/internal/metrics

url-shortener's People

Contributors

vrazdalovschi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.