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.
- 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
- Language: Go 1.23+
- Web Framework: Fiber v2
- Storage: Redis
- Logging: Uber Zap
- DI Framework: Uber fx
- Containerization: Docker
-
Clone the repository:
git clone https://github.com/tnfy-link/backend.git cd server
-
Start the services:
docker compose up --build -d
-
Prerequisites:
- Go 1.23 or later
- Redis server
-
Install dependencies:
go mod download
-
Configure environment variables:
cp .env.example .env # Edit .env with your configuration
-
Run the server:
go run main.go
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 is available through Swagger UI at https://tnfy-link.github.io/backend/ and at the /api/v1/docs
endpoint of the backend.
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 /api/v1/links/{id}/stats
Response:
{
"stats": {
"labels": {
"source": {
"google": 1
},
"medium": {
"cpc": 1
},
"campaign": {
"new_year": 1
}
},
"total": 1
}
}
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.
Built with ❤️ using Go and Codeium.