A high-performance Go-based URL redirector service with Redis-backed storage, supporting wildcard matching, security filtering, and multiple redirect types.
The application follows a clean architecture pattern with dependency injection:
cmd/server/ # Application entry point
internal/
├── app/ # Application assembly and startup
├── config/ # Configuration management
├── interfaces/ # Interface definitions
├── handlers/ # HTTP request handlers
├── services/ # Business logic services
├── storage/ # Data storage implementations
├── cache/ # Caching implementations
├── template/ # Template rendering
├── models/ # Data models
├── errors/ # Error types
└── tests/ # Unit and integration tests
# Run directly
go run ./cmd/server [port]
# Build binary
go build -o server ./cmd/server
./server [port]
# Build image
docker build -t redirector .
# Run with docker-compose (includes Redis)
docker-compose up
# Unit tests
go test ./internal/...
# Integration tests
go test -v ./internal/tests/...
# Benchmark tests
go test -bench=. ./tests/...
REDIS_HOST - Redis host (default: "redis")REDIS_PORT - Redis port (default: "6379")REDIS_DB - Redis database (default: "0")POWERBY - Service brandingCreate config.json based on config.json.example:
{
"name": "node-name",
"cache": true,
"ip": "server-ip",
"country": "server-country"
}
Records stored in Redis follow this structure:
{
"_id": "domain.com/path",
"value": "https://target.com",
"type": "301",
"handler": "redirect",
"blacklist": false,
"filters": ["nobot", "nowechat"],
"destinations": ["url1", "url2"],
"routing": "random",
"utm": {"source": "redirect"},
"params": {"ref": "redirector"}
}
domain.com/pathdomain.com/**.domain.com/*301/302/307/308 - HTTP redirectsframe - Iframe embeddingredirect_js - JavaScript redirecttxt - Plain text responsehtml - HTML content{host} - Full hostname{host.domain} - Top-level domain{host.sub} - Subdomain part{path}, {uri} - URL path{qs} - Query string{random_string} - Random 6-char stringThe refactored codebase provides:
internal/interfaces/internal/services/internal/app/app.gointernal/tests/Content type
Image
Digest
sha256:90060536b…
Size
18.9 MB
Last updated
3 months ago
docker pull redirhub/rapid