World Conquest Chronicles

World Conquest Chronicles

go-exercises-backend, v1.2

Back-end of the service for solving programming exercises.

Implement serving static files.

Change Log

  • server:
    • additional routing:
      • serving static files.

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;
      • 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);
    • representing:
      • in a JSON:
        • payloads:
          • of requests;
          • of responses;
      • as a plain text:
        • errors;
  • 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;
  • 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;
    • generate a token signing key automatically by default;
    • user model:
      • storing:
        • username (unique);
        • password hash:
          • generated using the bcrypt function;
  • databases:
  • 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;
  • utilities:
    • utility for managing users:
      • commands:
        • add a user:
          • parameters:
            • username;
            • password:
              • generate automatically by default;
            • password hashing cost;
            • generated password length;
  • distributing:

Usage

$ go-exercises-backend

Environment variables:

  • SERVER_STATIC_FILE_PATH — path to static files (default: ./static);
  • addresses:
    • SERVER_ADDRESS — server URI (default: :8080);
    • STORAGE_ADDRESSPostgreSQL connection URI (default: postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable);
    • MESSAGE_BROKER_ADDRESSRabbitMQ 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).

Repository

Link: https://github.com/thewizardplusplus/go-exercises-backend/tree/v1.2.

Content: code.

License: MIT.