go-exercises-backend, v1.1
Posted on

Back-end of the service for solving programming exercises.
Implement authentication that use the Bearer authentication scheme based on JSON Web Tokens; implement the utility for adding users.
Change Log
- RESTful API:
- models:
- task model:
- storing:
- author ID;
- operations:
- updating by an ID:
- allowed for its author only;
- deleting by an ID:
- allowed for its author only;
- updating by an ID:
- storing:
- solution model:
- storing:
- author ID;
- operations:
- getting all solutions by a task ID:
- filtered by a requesting author;
- getting a single solution by an ID:
- allowed for its author only;
- getting all solutions by a task ID:
- storing:
- task model:
- models:
- authentication:
- use the Bearer authentication scheme based on JSON Web Tokens:
- store in a JWT claims:
- expiration time claim;
- user claim:
- contains a whole user model;
- store in a JWT claims:
- generate a token signing key automatically by default;
- user model:
- storing:
- username (unique);
- password hash:
- generated using the bcrypt function;
- storing:
- use the Bearer authentication scheme based on JSON Web Tokens:
- utilities:
- utility for managing users:
- commands:
- add a user:
- parameters:
- username;
- password:
- generate automatically by default;
- password hashing cost;
- generated password length.
- parameters:
- add a user:
- commands:
- utility for managing users:
Features
- RESTful API:
- models:
- task model:
- storing:
- author ID;
- title;
- description;
- boilerplate code;
- test cases:
- all test cases are represented by a single string;
- operations:
- getting all tasks;
- getting a single task by an ID;
- creating;
- updating by an ID:
- allowed for its author only;
- deleting by an ID:
- allowed for its author only;
- storing:
- solution model:
- storing:
- author ID;
- task ID;
- code;
- correctness flag;
- testing result:
- represented by a string;
- operations:
- getting all solutions by a task ID:
- filtered by a requesting author;
- getting a single solution by an ID:
- allowed for its author only;
- creating;
- updating by an ID:
- performed by a queue consumer only (see below);
- getting all solutions by a task ID:
- storing:
- task model:
- representing:
- in a JSON:
- payloads:
- of requests;
- of responses;
- payloads:
- as a plain text:
- errors;
- in a JSON:
- models:
- server:
- storing settings in environment variables;
- supporting graceful shutdown;
- logging:
- logging requests;
- logging errors;
- panics:
- recovering on panics;
- logging of panics;
- authentication:
- use the Bearer authentication scheme based on JSON Web Tokens:
- store in a JWT claims:
- expiration time claim;
- user claim:
- contains a whole user model;
- store in a JWT claims:
- generate a token signing key automatically by default;
- user model:
- storing:
- username (unique);
- password hash:
- generated using the bcrypt function;
- storing:
- use the Bearer authentication scheme based on JSON Web Tokens:
- databases:
- storing data in the PostgreSQL database;
- interaction with queues:
- using the RabbitMQ message broker;
- common properties:
- automatic declaring of the used queues;
- passing of a message data in JSON;
- operations:
- producing solutions:
- concurrent producing;
- consuming solution results:
- concurrent consuming;
- once requeue the solution on failure;
- producing solutions:
- utilities:
- utility for managing users:
- commands:
- add a user:
- parameters:
- username;
- password:
- generate automatically by default;
- password hashing cost;
- generated password length;
- parameters:
- add a user:
- commands:
- utility for managing users:
- distributing:
- Docker image;
- Docker Compose configuration.
Usage
$ go-exercises-backend
Environment variables:
- addresses:
SERVER_ADDRESS— server URI (default::8080);STORAGE_ADDRESS— PostgreSQL connection URI (default:postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable);MESSAGE_BROKER_ADDRESS— RabbitMQ connection URI (default:amqp://rabbitmq:rabbitmq@localhost:5672);
- solution registration:
SOLUTION_REGISTER_BUFFER_SIZE— solution registration channel capacity (default:1000);SOLUTION_REGISTER_CONCURRENCY— amount of solution registration threads (default:1000);
- authorization:
AUTHORIZATION_TOKEN_SIGNING_KEY— authorization token signing key (is generated automatically if empty; default: empty);AUTHORIZATION_TOKEN_TTL— authorization token TTL (default:24h).
Installation of the go-exercises-user-manager Tool
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-exercises-backend.git
$ cd go-exercises-backend
Install dependencies with the dep tool:
$ dep ensure -vendor-only
Build the utility:
$ go install ./cmd/go-exercises-user-manager
Usage of the go-exercises-user-manager Tool
$ go-exercises-user-manager -h | --help
$ go-exercises-user-manager add [options]
Commands:
add— add the user.
Options:
-h,--help— show the context-sensitive help message and exit;-u STRING,--username STRING— username;-p STRING,--password STRING— user password (default: generated automatically);-c INTEGER,--cost INTEGER— cost of the user password hashing (range: from 4 to 31 inclusive; default:10);-l INTEGER,--length INTEGER— length of the user password to be generated (minimum: 6; default:6).
Environment variables:
STORAGE_ADDRESS— PostgreSQL connection URI (default:postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable).
Repository
Link: https://github.com/thewizardplusplus/go-exercises-backend/tree/v1.1.
Content: code.
License: MIT.
Screenshots
Adding a user via the go-exercises-user-manager tool
