Skip to content

Latest commit

 

History

22 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

URL Shortener

Go Version License Status

A lightweight and efficient URL shortening service built with Go. This service allows you to convert long URLs into short, manageable links.

Features

  • Generate short URLs from long links
  • SQLite-based storage for simplicity
  • Clean and minimal configuration
  • Structured logging with log/slog
  • Environment-based configuration

Project Stack

  • Language: Go 1.25
  • Configuration: cleanenv
  • Logging: log/slog (standard library)
  • Storage: SQLite
  • Router: chi, chi/render
  • Environment: godotenv

Getting Started

Prerequisites

  • Go 1.25 or higher
  • SQLite3

Installation

  1. Clone the repository:
git clone <repository-url>
cd url-shortener
  1. Install dependencies:
go mod download
  1. Set up environment variables:
cp .env.example .env

The .env file should contain:

CONFIG_PATH=./config/local.yaml

Configuration

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: 60s

Running the Application

go run cmd/url-shortener/main.go

Or build and run:

go build -o url-shortener cmd/url-shortener/main.go
./url-shortener

Project Structure

.
├── cmd/
│   └── url-shortener/       # Application entrypoint
├── config/                   # Configuration files
│   └── local.yaml
├── internal/
│   ├── config/              # Configuration loading
│   └── storage/             # Database layer
├── .env                     # Environment variables
└── go.mod

Future Roadmap

  • 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

Development

Running Tests

go test ./...

Code Formatting

go fmt ./...

Linting

golangci-lint run

License

This project is licensed under the MIT License.

About

A lightweight URL shortening service with SQLite storage. Built with Go, chi router, and cleanenv.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages