Skip to content

wavly/shawty

Repository files navigation

Shawty

Shawty is a URL shortener built using Golang, Turso and HTMX. It provides a simple web interface for shortening URLs, tracking their usage, and offering statistics about shortened URLs.

Features

  • Web UI with Golang's html/template: A minimalistic web interface built using Go's standard html/template package and Tailwind.

  • URL Click Statistics: Keep track of how many times each shortened URL is accessed.

  • Caching: Using Memcached for faster redirections and fewer database calls, by caching the results of redirecting requests to the original URL.

  • Input Validation: Checks if the URL is a valid URL schema. It only allows https:// URLs. And also checks if the URL contains a valid TLD.

Getting Started

Prerequisites

Installation and Setup

  1. Clone the repository:

    git clone https://github.com/wavly/shawty.git
    cd shawty
  2. Set ENV Variables: Get the database URL and Token: Turso Docs

    cp .env .env.local
  3. Install the dependencies:

    go mod tidy
  4. Start the Memcached listener:

    memcached # default port is: 11211
  5. Run the server:

    go run .
  6. Access the web interface on port: 1234:

    curl -i http://localhost:1234/

Development

Use the Makefile to run/build the web server.

Requirements

  • Watchexec - A file watcher for restarting and running the web server when the source files are updated.
  • Bun - Bun package manager (or npm,pmpm) for installing and watching static content for tailwind classes.
  • Sqlc - Generating type-safe code from SQL.

Commands

  • make server to start the server in watch mode
  • make tailwind to watch for tailwind classes
  • make tailmini to minify the generated tailwind CSS file

Contributing

We welcome any contributions to this project! For major changes, please open an issue first to discuss what you would like to change.

LICENSE