Skip to content

vstdy/go-shortener

Repository files navigation

Shortener

The application is a tool that creates a short, unique URL that will redirect to the specific website of your choosing.
Is a project of the course

REST API

By default, server starts at 8080 HTTP port with the following endpoints:

  • POST / - create shortcut for url from text/plain body;
  • POST /api/shorten - create shortcut for url from application/json body;
  • POST /api/shorten/batch - create shortcuts for urls batch from application/json body;
  • GET /{urlID} - follow origin url from shortcut;
  • GET /api/user/urls - get urls created by current user;
  • DELETE /api/user/urls - remove urls created by current user with given ids;
  • GET /ping - check connection to database;

For details check out http-client.http file

Code

Packages used

App architecture and configuration:

Networking:

SQL database interface provider:

  • bun - database client;

Testing:

CLI

All CLI commands have the following flags:

  • --log_level: (optional) logging level (default: info);
  • --config: (optional) path to configuration file (default: ./config.toml);
  • --timeout: (optional) request timeout (default: 5s);
  • -d --database_dsn: (optional) database source name (default: postgres://user:password@localhost:5432/shortener?sslmode=disable);

Root only command flags:

  • -a --server_address: (optional) server address (default: 0.0.0.0:8080);
  • -b --base_url: (optional) base URL (default: http://127.0.0.1:8080);
  • -s --storage_type: (optional) storage type (default: psql);
  • -f --file_storage_path: (optional) file storage path (default: ./storage/file/storage_file.txt);

If config file not specified, defaults are used. Defaults can be overwritten using ENV variables.

Migrations

shortener migrate --config ./my-confs/config-1.toml

Command migrates DB to the latest version

gRPC client

  1. Shorten given url.

    shortener client shorten https://lengthy-url.com/
    

    Arguments:

    • args[0]: url to shorten;
  2. Shorten given urls batch.

    shortener client shorten batch https://lengthy-url-1.com/ https://lengthy-url-2.com/
    

    Arguments:

    • args[0] args[1]...: urls to shorten
  3. Return original url from shortened url.

    shortener client get original_url http://127.0.0.1:8080/gw/1
    

    Arguments:

    • args[0]: shortened url;
  4. Return user's urls.

    shortener client get users_urls
    
  5. Delete user's urls.

    shortener client delete 1 3
    

    Arguments:

    • args[0] args[1]...: ids of urls to delete

Flags:

  • -t --token: (optional) user's token;

How to run

Docker

docker-compose -f build/docker-compose.yml up

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages