Categorygithub.com/tnfy-link/backend
repositorypackage
0.5.0
Repository: https://github.com/tnfy-link/backend.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# README

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:

VariableDescriptionDefault
HTTP__ADDRESSHTTP server listen address:3000
HTTP__PROXY_HEADERHTTP proxy header nameempty
HTTP__PROXIESComma-separated list of proxiesempty
API__CORS_ALLOW_ORIGINSCORS allowed originsempty
STORAGE__URLRedis connection URLredis://localhost:6379/0
LINKS__HOSTNAMEBase hostname for generated linkshttp://localhost:3001
LINKS__TTLTime-to-live for shortened links168h

📝 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.