Skip to content

wavly/surf

Repository files navigation

Surf

Surf 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 go-cache for faster redirections and fewer database calls, by caching the results of redirecting requests.

  • 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/surf.git
    cd surf
  2. Set ENV Variables:

    Get the database URL and Token from: Turso Docs. Only needed if you're going to run the server in prod mode else the server would create a temporary sqlite3 database in the project directory

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

    go mod tidy
  4. Run the server:

    make build
  5. Access the web interface on port: 1920:

    xdg-open http://localhost:1920

Development

Use the make command to run/build the web server.

Note

Make sure the ENVIROMENT variable in .env is set to dev in order run the server in development mode.

Requirements

Tools you'll be needing for development:

  • Sqlc - Generating type-safe code from SQL.
  • Bun - Bun package manager (or npm,pmpm) for JavaScript dependencies.
  • Templ - The HTML templating language and live-reloading

Make 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
  • make sqlc to generate type safe SQL Go-code.
  • make build to build the server

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