Back-end of the service for solving programming exercises.
- 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:
- calculate a total correctness flag based on all solutions of a requesting author;
- sort the results by creation time in descending order;
- process pagination:
- implemented using an offset and a limit;
- getting a single task by an ID:
- calculate a total correctness flag based on all solutions of a requesting author;
- creating:
- automatically format a task boilerplate code;
- updating by an ID:
- allowed for its author only;
- automatically format a task boilerplate code;
- deleting by an ID:
- allowed for its author only;
- getting all tasks:
- 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:
- allow a solution task author to get solutions of other authors;
- sort the results by creation time in descending order;
- process pagination:
- implemented using an offset and a limit;
- filtered by a requesting author:
- getting a single solution by an ID:
- allowed for:
- solution author;
- solution task author;
- allowed for:
- creating:
- automatically format a solution code;
- updating by an ID:
- performed by a queue consumer only (see below);
- formatting a solution code;
- 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:
- additional routing:
- 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:
- 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;
- flag indicating whether the user is disabled or not;
- 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;
- password hashing cost;
- flag indicating the need to generate a password;
- generated password length;
- flag indicating whether the user is disabled or not;
- parameters:
- update a user:
- parameters:
- username;
- new username;
- password;
- password hashing cost;
- flag indicating the need to generate a password;
- generated password length;
- flag indicating whether the user is disabled or not;
- flag indicating whether the user is enabled or not;
- can update the user fields individually;
- parameters:
- add a user:
- commands:
- utility for managing users:
- distributing:
- Docker image;
- Docker Compose configuration.
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 project:
$ go install ./...
The necessary tables will be created automatically on service starting.
Then run the manual migration to create a few example tasks (optionally):
$ ./tools/migrate.sh -h | --help
$ ./tools/migrate.sh
Options:
-h
,--help
— show the help message and exit.
Environment variables:
PATH_TO_MIGRATIONS
— path to migrations (default:./migrations
);STORAGE_ADDRESS
— PostgreSQL connection URI (default:postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable
).
The following example tasks will be created:
- Sum of Two Numbers (Test Task)
- Sum of Array
- Product of Array
- Minimum of Array
- Maximum of Array
- Index of Array Minimum
- Index of Array Maximum
- Search in Array
- Search in Array (Last Occurrence)
- Filtering of Array
- Filtering of Array (In-place)
- Removing of Duplicates
- Removing of Duplicates (In-place)
The solutions for the example tasks: docs/_solutions.
$ go-exercises-backend
Environment variables:
SERVER_STATIC_FILE_PATH
— path to static files (default:./static
);- 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
).
API description:
- RabbitMQ API description in the AsyncAPI format: docs/async_api.yaml;
- web API description:
- in the Swagger format: docs/swagger.yaml;
- in the format of a Postman collection: docs/postman_collection.json.
- go-exercises-manager — utility for managing users
The MIT License (MIT)
Copyright © 2021-2022 thewizardplusplus