package
module
Version:
v0.0.0-...-6dc70a1
Opens a new window with list of versions in this module.
Published: Aug 18, 2021
License: MIT
Opens a new window with license information.
Imports: 0
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
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;
- 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_ADDRESS
— Redis connection URI (default: localhost:6379
);
STORAGE_ADDRESS
— MongoDB connection URI (default: mongodb://localhost:27017
);
COUNTER_ADDRESS
— etcd 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
- URL Shortener System Design.
- Generating Globally Unique Identifiers for Use with MongoDB.
License
The MIT License (MIT)
Copyright © 2019-2021 thewizardplusplus
Documentation
¶
There is no documentation for this package.
Source Files
¶
Directories
¶
cmd
|
|
|
|
|
|
gateways
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Click to show internal directories.
Click to hide internal directories.