Skip to content

High-performance URL shortener service backend built with Go, featuring Redis storage, UTM label support, and Docker deployment. Fast, reliable, and easily configurable.

License

Notifications You must be signed in to change notification settings

tnfy-link/backend

Repository files navigation

tnfy.link

Go Report Card GitHub license Go Version Docker Image Website

tnfy.link logo

The backend of a high-performance URL shortener service built with Go, using modern technologies and best practices. This service provides fast and reliable URL shortening capabilities with Redis-based storage.

🚀 Features

  • High Performance: Built with Go and Fiber framework for maximum speed
  • Statistics: UTM labels support for analytics
  • Redis Storage: Fast and reliable link storage with configurable TTL
  • Base58 Encoding: Human-friendly short URLs using Base58 encoding
  • Docker Support: Easy deployment with Docker and Docker Compose
  • Configurable: Environment-based configuration for flexibility
  • Structured Logging: Comprehensive logging with Zap logger
  • Dependency Injection: Clean architecture using Uber's fx framework

🛠 Tech Stack

  • Language: Go 1.23+
  • Web Framework: Fiber v2
  • Storage: Redis
  • Logging: Uber Zap
  • DI Framework: Uber fx
  • Containerization: Docker

🏃‍♂️ Quick Start

Using Docker Compose with Local Build

  1. Clone the repository:

    git clone https://github.com/tnfy-link/backend.git
    cd server
  2. Start the services:

    docker compose up --build -d

Manual Setup

  1. Prerequisites:

    • Go 1.23 or later
    • Redis server
  2. Install dependencies:

    go mod download
  3. Configure environment variables:

    cp .env.example .env
    # Edit .env with your configuration
  4. Run the server:

    go run main.go

⚙️ Configuration

Configuration is done through environment variables:

Variable Description Default
HTTP__ADDRESS HTTP server listen address :3000
HTTP__PROXY_HEADER HTTP proxy header name empty
HTTP__PROXIES Comma-separated list of proxies empty
API__CORS_ALLOW_ORIGINS CORS allowed origins empty
STORAGE__URL Redis connection URL redis://localhost:6379/0
LINKS__HOSTNAME Base hostname for generated links http://localhost:3001
LINKS__TTL Time-to-live for shortened links 168h
ID__PROVIDER ID provider (random or combined) random

📝 API Documentation

API documentation is available through Swagger UI at https://tnfy-link.github.io/backend/ and at the /api/v1/docs endpoint of the backend.

Shorten URL

POST /api/v1/links
Content-Type: application/json

{
  "link": {
    "targetUrl": "https://docs.sms-gate.app"
  }
}

Response:

{
  "link": {
    "id": "3uqH4m",
    "targetUrl": "https://docs.sms-gate.app",
    "url": "https://tnfy.link/3uqH4m",
    "createdAt": "2024-12-09T12:53:12.76979501Z",
    "validUntil": "2024-12-16T12:53:12.76979501Z"
  }
}

Get Link By ID

GET /api/v1/links/{id}

Response:

{
  "link": {
    "id": "3uqH4m",
    "targetUrl": "https://docs.sms-gate.app",
    "url": "https://tnfy.link/3uqH4m",
    "createdAt": "2024-12-09T12:53:12.76979501Z",
    "validUntil": "2024-12-16T12:53:12.76979501Z"
  }
}

Get Statistics

GET /api/v1/links/{id}/stats

Response:

{
  "stats": {
    "labels": {
      "source": {
        "google": 1
      },
      "medium": {
        "cpc": 1
      },
      "campaign": {
        "new_year": 1
      }
    },
    "total": 1
  }
}

🤝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.


Built with ❤️ using Go and Codeium.

About

High-performance URL shortener service backend built with Go, featuring Redis storage, UTM label support, and Docker deployment. Fast, reliable, and easily configurable.

Topics

Resources

License

Stars

Watchers

Forks

Packages