backend

command module
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2025 License: Apache-2.0 Imports: 1 Imported by: 0

README ΒΆ

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

Documentation ΒΆ

The Go Gopher

There is no documentation for this package.

Directories ΒΆ

Path Synopsis
Package api Code generated by swaggo/swag.
Package api Code generated by swaggo/swag.
api
id

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL