World Conquest Chronicles

World Conquest Chronicles

go-link-shortener-backend, v1.8

Back-end of the service for shorting links.

Adding transformations of values received from a distributed counter, refactoring and adding bulky testing.

Change Log

  • adding transformations of values received from a distributed counter:
    • using linear transformations:
      • multiplication;
      • shift;
  • removing:
    • generating link codes:
      • removing using a version 4 UUID;
      • using sequential counters:
        • removing formatting a counter as an integer number in the 10 base;
  • refactoring:
    • extracting the counters package:
      • moving the generators.chunkedCounter structure to the counters.ChunkedCounter structure;
      • extracting the counters.CounterGroup structure from the generators.DistributedGenerator structure;
    • using external packages:
      • replacing Printer interfaces to the special package;
      • extracting HTTP utility functions to the single package;
  • testing:
    • bulky testing:
      • adding a bulky test of the generators.DistributedGenerator structure;
      • adding an integration bulky test of link creating;
    • Travis CI configuration:
      • using data race detection;
      • using the dep tool;
  • improving repository decor:
    • adding the change log.

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;
  • 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:

Usage

$ go-link-shortener

Environment variables:

  • SERVER_ADDRESS — server URI (default: :8080);
  • SERVER_STATIC_PATH — path to the project's front-end (default: ./static);
  • CACHE_ADDRESSRedis connection URI (default: localhost:6379);
  • 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);
  • STORAGE_ADDRESSMongoDB connection URI (default: mongodb://localhost:27017);
  • COUNTER_ADDRESSetcd connection URI (default: localhost:2379);
  • 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).

Repository

Link: https://github.com/thewizardplusplus/go-link-shortener-backend/tree/v1.8.

Content: code.

License: MIT.