A minimal URL shortener written in Go that uses YAML files as a database.
- Fast HTTP redirects using Fiber web framework
- Simple YAML-based URL mapping
- CLI interface with Cobra
- Docker support
- Minimal dependencies
git clone <repository-url>
cd minilink
go mod download
go build -o minilink
Edit the links.yaml
file to add your URL routing rules:
routes:
gh:
default: "https://github.com"
rules:
- query: "x=y"
url: "https://github.com/Meraj"
passthrough: false
gf:
default: "https://github.com"
rules:
- query: "x=y"
url: "https://github.com/Meraj"
passthrough: true
yt:
default: "https://youtube.com"
rules:
- query: "v=x"
url: "https://google.com"
passthrough: false
- query: "y=2"
url: "https://meraj.com"
passthrough: false
Start the server with default settings:
./minilink serve
Or specify custom port and config file:
./minilink serve --port 3000 --config my-links.yaml
--port, -p
: Port to run the server on (default: 8080)--config, -c
: Path to the YAML config file (default: links.yaml)
GET /
: Health check endpointGET /:shortcode
: Redirects to the configured URL
Once the server is running on port 8080:
Basic redirects:
- Visit
http://localhost:8080/gh
→ redirects tohttps://github.com
- Visit
http://localhost:8080/google
→ redirects tohttps://google.com
Query-based routing:
- Visit
http://localhost:8080/gh?x=y
→ redirects tohttps://github.com/Meraj
- Visit
http://localhost:8080/gf?x=y
→ redirects tohttps://github.com/Meraj?x=y
(with passthrough) - Visit
http://localhost:8080/yt?v=x
→ redirects tohttps://google.com
- Visit
http://localhost:8080/yt?y=2
→ redirects tohttps://meraj.com
Error handling:
- Visit
http://localhost:8080/invalid
→ returns 404 error
docker build -t minilink .
docker run -p 8080:8080 -v $(pwd)/links.yaml:/app/links.yaml minilink
minilink/
├── main.go # Entry point
├── cmd/
│ └── serve.go # Serve command
├── internal/
│ ├── config/
│ │ └── config.go # YAML config loader
│ └── server/
│ └── server.go # HTTP server
├── links.yaml # URL database
├── go.mod # Go module
├── README.md # This file
└── Dockerfile # Container config
Edit the links.yaml
file to add new routing rules:
routes:
mysite:
default: "https://mywebsite.com"
rules:
- query: "page=about"
url: "https://mywebsite.com/about"
passthrough: false
blog:
default: "https://myblog.com"
rules:
- query: "tag=tech"
url: "https://myblog.com/tech"
passthrough: true
Route Configuration:
default
: The URL to redirect to when no query rules matchrules
: Array of query-based routing rulesquery
: Query parameter pattern to match (e.g., "x=y")url
: Target URL for this rulepassthrough
: If true, append original query parameters to the target URL
MIT License