Fast, SQLite-backed URL shortener written in Go. Compatible with the YOURLS API, with click tracking and an HTMX admin UI. Includes authentication, CSV import, optional GeoIP, and cached redirects.
  • Go 88.9%
  • HTML 7%
  • Shell 3.5%
  • Makefile 0.3%
  • Dockerfile 0.3%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-10-05 22:58:31 +05:30
cmd/shortlinks random slug, redirect loop check 2026-10-05 22:58:31 +05:30
internal random slug, redirect loop check 2026-10-05 22:58:31 +05:30
scripts init 2026-10-03 20:15:36 +05:30
specs init 2026-10-03 20:15:36 +05:30
.dockerignore init 2026-10-03 20:15:36 +05:30
.gitignore init 2026-10-03 20:15:36 +05:30
config.example.yaml random slug, redirect loop check 2026-10-05 22:58:31 +05:30
Dockerfile init 2026-10-03 20:15:36 +05:30
generate.go init 2026-10-03 20:15:36 +05:30
go.mod init 2026-10-03 20:15:36 +05:30
go.sum init 2026-10-03 20:15:36 +05:30
LICENSE init 2026-10-03 20:15:36 +05:30
Makefile init 2026-10-03 20:15:36 +05:30
README.md init 2026-10-03 20:15:36 +05:30
sqlc.yaml init 2026-10-03 20:15:36 +05:30

shortlinks

A fast, SQLite-backed URL shortener compatible with the YOURLS API. It includes short-link redirects, click tracking, an HTMX admin interface, authentication, CSV import, and optional GeoIP lookup.

Run

Requires Go, CGO, and a C compiler.

make dev

The service starts at http://localhost:8080. Create a link with:

curl -X POST http://localhost:8080/api \
  -d action=shorturl \
  -d format=json \
  --data-urlencode url=https://example.com

Use DEV_ARGS to override defaults:

make dev DEV_ARGS='--addr :8081 --public-url http://localhost:8081 --sqlite-path data/dev.db'

Configuration

Configuration is loaded in this order: defaults, YAML file, SHORTLINKS_ environment variables, then CLI flags. See config.example.yaml for all options.

The API is available at /api and the YOURLS-compatible /yourls-api.php. Supported actions are shorturl, stats, db-stats, url-stats, expand, and version; output formats are JSON, JSONP, XML, and plain text.

Migrations run automatically at startup and can also be managed manually:

go run ./cmd/shortlinks migrate up --sqlite-path data/shortlinks.db
go run ./cmd/shortlinks migrate down --sqlite-path data/shortlinks.db

Development

make generate   # regenerate API and database code
make spec-lint  # lint the OpenAPI specification
make test
make bench

Database definitions are in specs/db; the API specification is in specs/openapi/openapi.yaml.