Skip to content

mradigen/chota

Repository files navigation

chota

A URL shortener written in Go. Supporting both in-memory and PostgreSQL storage backends.

TODO

  • Wait for Postgres DB to come live before trying to connect
  • Modify in memory storage to use sync.RWMutex instead of maps
  • Create a frontend under /website
  • Return saved slug if URL already exists in Storage
  • Ability to choose custom slug
  • Debug logging
  • Add a deploy/docker-compose.yml

Table of Contents

Usage

The following endpoints are available:

  • GET /shorten?url=:URL: Shorten a new URL.
  • GET /:slug: Redirect to the original URL.

Example:

curl 'http://localhost:8080/shorten?url=https://example.com'

Response:

{ "short_url": "pvog" }

Installation

Clone the repository:

git clone https://github.com/mradigen/chota
cd chota

Docker

  1. Build the Docker image:

    make docker
  2. Copy the .env.example file and edit it as needed (refer configuration):

    cp .env.example .env
  3. Run the Docker container:

    docker run -p 8080:8080 --env-file=.env chota

Native

  1. Build the project:

    make build
  2. Run:

    ./chota

Configuration

The application supports environment-based configuration:

Variable Default Description
PORT 8080 Port for the HTTP server.
STORAGE_MODE memory Storage backend: memory or postgres.
DATABASE_URL postgres://... Connection string for PostgreSQL. Used only if STORAGE_MODE=postgres
BIND_ADDRESS 127.0.0.1 Address to listen on.
DEBUG (unimplemented) false Log debug activity.

Deployment

Kubernetes

Use the provided kubernetes.yml file to deploy the application to a Kubernetes cluster:

make kubernetes

or

kubectl apply -f deploy/kubernetes.yml

Development

Run

make run

Testing:

Currently there is a very basic test setup. Run the unit and integration tests using:

make test

Contributing

Contributions are highly encouraged! Please open an issue or submit a pull request with your changes.

About

URL shortener written in Go

Topics

Resources

Stars

Watchers

Forks