World Conquest Chronicles

World Conquest Chronicles

go-link-shortener-backend, v1.11

Back-end of the service for shorting links.

Supporting individual data storages for each server via specifying of the source server in a link.

Change Log

  • 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.

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:

API Description

API description in the Swagger format:

swagger: "2.0"
info:
  title: go-link-shortener API
  version: 1.11.0
  license:
    name: MIT
host: localhost:8080
basePath: /api/v1
paths:
  /links/:
    post:
      consumes:
        - application/json
      parameters:
        - description: link data
          in: body
          name: data
          required: true
          schema:
            $ref: "#/definitions/handlers.LinkCreatingRequest"
      produces:
        - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: "#/definitions/entities.Link"
        "400":
          description: Bad Request
          schema:
            $ref: "#/definitions/presenters.ErrorResponse"
        "500":
          description: Internal Server Error
          schema:
            $ref: "#/definitions/presenters.ErrorResponse"
  /links/{code}:
    get:
      parameters:
        - description: link code
          in: path
          name: code
          required: true
          type: string
      produces:
        - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: "#/definitions/entities.Link"
        "400":
          description: Bad Request
          schema:
            $ref: "#/definitions/presenters.ErrorResponse"
        "404":
          description: Not Found
          schema:
            $ref: "#/definitions/presenters.ErrorResponse"
        "500":
          description: Internal Server Error
          schema:
            $ref: "#/definitions/presenters.ErrorResponse"
  /links/{serverID}:{code}:
    get:
      parameters:
        - description: server ID
          in: path
          name: serverID
          required: true
          type: string
        - description: link code
          in: path
          name: code
          required: true
          type: string
      produces:
        - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: "#/definitions/entities.Link"
        "400":
          description: Bad Request
          schema:
            $ref: "#/definitions/presenters.ErrorResponse"
        "404":
          description: Not Found
          schema:
            $ref: "#/definitions/presenters.ErrorResponse"
        "500":
          description: Internal Server Error
          schema:
            $ref: "#/definitions/presenters.ErrorResponse"
definitions:
  entities.Link:
    type: object
    properties:
      ServerID:
        type: string
      Code:
        type: string
      URL:
        type: string
  handlers.LinkCreatingRequest:
    type: object
    properties:
      URL:
        type: string
  presenters.ErrorResponse:
    type: object
    properties:
      Error:
        type: string

Repository

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

Content: code.

License: MIT.