A lightweight and efficient URL shortening service built with Go. This service allows you to convert long URLs into short, manageable links.
- Generate short URLs from long links
- SQLite-based storage for simplicity
- Clean and minimal configuration
- Structured logging with
log/slog - Environment-based configuration
- Language: Go 1.25
- Configuration: cleanenv
- Logging:
log/slog(standard library) - Storage: SQLite
- Router: chi, chi/render
- Environment: godotenv
- Go 1.25 or higher
- SQLite3
- Clone the repository:
git clone <repository-url>
cd url-shortener- Install dependencies:
go mod download- Set up environment variables:
cp .env.example .envThe .env file should contain:
CONFIG_PATH=./config/local.yaml
The application uses a YAML configuration file located at config/local.yaml:
env: "local"
storage_path: "./storage/storage.db"
http_server:
address: "localhost:8080"
timeout: 4s
idle_timeout: 60sgo run cmd/url-shortener/main.goOr build and run:
go build -o url-shortener cmd/url-shortener/main.go
./url-shortener.
├── cmd/
│ └── url-shortener/ # Application entrypoint
├── config/ # Configuration files
│ └── local.yaml
├── internal/
│ ├── config/ # Configuration loading
│ └── storage/ # Database layer
├── .env # Environment variables
└── go.mod
- PostgreSQL Support: Replace SQLite with PostgreSQL for production-ready scalability
- Basic Authentication: Add Basic Auth for protected endpoints
- Custom Short URLs: Allow users to specify custom short codes
- Analytics: Track click statistics and analytics
- Rate Limiting: Implement rate limiting for API endpoints
- REST API: Full REST API with comprehensive documentation
- Docker Support: Containerize the application
go test ./...go fmt ./...golangci-lint runThis project is licensed under the MIT License.