go-link-shortener-backend, v1.0
Posted on

Back-end of the service for shorting links.
Major version.
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 a version 4 UUID;
- server:
- storing settings in environment variables;
- supporting graceful shutdown;
- 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_ADDRESS— server URI (default::8080);CACHE_ADDRESS— Redis connection URI (default:localhost:6379);STORAGE_ADDRESS— MongoDB connection URI (default:mongodb://localhost:27017).
API Description
API description in the Swagger format:
swagger: "2.0"
info:
title: go-link-shortener API
version: 1.0.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"
"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:
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.0.
Content: code.
License: MIT.
Screenshots
POST /links/
