/zatch

URL shortener built with Go

Primary LanguageGo

URL Shortener

What it uses

  • Redis for storing tasks;
  • Asynq for enqueuing tasks;
  • Fiber for handling HTTP requests;

Environment Variables

You need to create .env file for development and put these variables there (but with real values)

POSTGRES_PASSWORD=db_password
POSTGRES_USER=db_user
POSTGRES_DB=db_name
DATABASE_HOST=localhost

REDIS_HOST=localhost
REDIS_PORT=6379

For development file called - .env For production - .env.production

Start in dev mode

make dev

this will start database and redis. After that, you need to manually run go run main.go

Build for production

make build
make start

Routes

GET /api/urls

Returns all urls from database

POST /api/shorten

Creates new url

Example body

{
  "url": "https://github.com",
  "name": "gh",
  "auto_delete": 30
}

name and auto_delete are optional.

auto_delete should be a number in minutes.

GET /api/:shortId

Returns url object by its short id

DELETE /api/:id

Deletes url by its id

GET /:shortId

Finds url by shortId and redirects to long url