linkshortener

package module
v0.0.0-...-6dc70a1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2021 License: MIT Imports: 0 Imported by: 0

README

GoDoc Go Report Card Build Status codecov

Back-end of the service for shorting links.

Features

  • RESTful API:
    • link model:
      • creating by an URL;
      • getting by a code;
    • representing in a JSON:
      • payloads:
        • of requests;
        • of responses;
      • errors;
  • generating link codes:
    • using sequential counters:
      • formatting:
        • formatting a counter as an integer number in the 62 base;
      • storing:
        • storing in a database only counters chunks;
        • storing counters themselves in memory;
      • sharding:
        • sharding counters chunks;
        • selecting a shard of a counter chunk at random;
  • sharding links across multiple servers (optionally):
    • supporting individual data storages for each server:
    • supporting specifying of the source server in a link:
      • returning the server ID on link generating;
      • ignoring the server ID:
        • on link getting;
        • on redirecting to a link;
  • server:
    • additional routing:
      • redirecting to the link URL by its code;
      • serving static files;
    • storing settings in environment variables;
    • supporting graceful shutdown;
    • logging:
      • logging requests;
      • logging errors;
    • panics:
      • recovering on panics;
      • logging of panics;
  • databases:
    • storing links in the MongoDB database;
    • storing counters chunks in the etcd database:
      • using a record version as a counter chunk;
    • caching links in the Redis database;
  • distributing:

Installation

Prepare the directory:

$ mkdir --parents "$(go env GOPATH)/src/github.com/thewizardplusplus/"
$ cd "$(go env GOPATH)/src/github.com/thewizardplusplus/"

Clone this repository:

$ git clone https://github.com/thewizardplusplus/go-link-shortener-backend.git
$ cd go-link-shortener-backend

Install dependencies with the dep tool:

$ dep ensure -vendor-only

Build the project:

$ go install ./...

Usage

$ go-link-shortener

Environment variables:

  • SERVER_ID — server ID;
  • SERVER_STATIC_PATH — path to the project's front-end (default: ./static);
  • addresses:
    • SERVER_ADDRESS — server URI (default: :8080);
    • CACHE_ADDRESSRedis connection URI (default: localhost:6379);
    • STORAGE_ADDRESSMongoDB connection URI (default: mongodb://localhost:27017);
    • COUNTER_ADDRESSetcd connection URI (default: localhost:2379);
  • time to live of links in Redis:
    • CACHE_TTL_CODE — time to live of links in Redis, stored by their code (e.g. 72h3m0.5s; default: 1h);
    • CACHE_TTL_URL — time to live of links in Redis, stored by their URL (e.g. 72h3m0.5s; default: 1h);
  • settings of distributed counters:
    • COUNTER_COUNT — count of distributed counters (default: 2);
    • COUNTER_CHUNK — step of a distributed counter (default: 1000);
    • COUNTER_RANGE — range of a distributed counter (default: 1000000000).

API Description

API description:

Bibliography

  1. URL Shortener System Design.
  2. Generating Globally Unique Identifiers for Use with MongoDB.

License

The MIT License (MIT)

Copyright © 2019-2021 thewizardplusplus

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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