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.
-
Web UI with Golang's
html/template: A minimalistic web interface built using Go's standardhtml/templatepackage 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.
-
Clone the repository:
git clone https://github.com/wavly/surf.git cd surf -
Set ENV Variables:
Get the database URL and Token from: Turso Docs. Only needed if you're going to run the server in
prodmode else the server would create a temporarysqlite3database in the project directorycp .env.example .env
-
Install the dependencies:
go mod tidy
-
Build & Run the server:
make build && ./surf -
Access the web interface on port:
1920:xdg-open http://localhost:1920
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.
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 serverto start the server in watch modemake tailwindto watch for tailwind classesmake tailminito minify the generated tailwind CSS filemake sqlcto generate type safe SQL Go-code.make buildto build the server
We welcome any contributions to this project! For major changes, please open an issue first to discuss what you would like to change.
- Surf is Licensed under MIT