# README
go-link-shortener-backend
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;
- payloads:
- link model:
- 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;
- formatting:
- using sequential counters:
- sharding links across multiple servers (optionally):
- 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;
- additional routing:
- databases:
- distributing:
- Docker image;
- Docker Compose configuration.
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:
- time to live of links in Redis:
- 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:
- in the Swagger format: docs/swagger.yaml;
- in the format of a Postman collection: docs/postman_collection.json.
Bibliography
License
The MIT License (MIT)
Copyright © 2019-2021 thewizardplusplus