URL Shortener allows users to input a long URL and receive a shortened version of it.
clone the repo
Run using Docker :
docker-compose upStart Redis:
docker run -d -p 6379:6379 --name redis redisinstall go dep
go mod tidyrun the server
go run main.goServer starts on http://localhost:8080- Go
- Redis
- Docker
- HTML, CSS, JS (This part was vibecoded)
- The Main concept is taking some long URL like http://{domainName}/{LongURL} and make it http://localhost:8080/{shortURL}
- the request come with the longURL so i take this request and use fnv-1a hash for the longURL and it output somelong numbers too so i take the first 6 characters of the hex hash
- on redis i store the URL like this originalURL : ShortURL, ShortURL : OriginalURL for the mapping between the two of them so when i click the short URL it redirect to the longURL using this mapping on the handler
1- POST /shorten : Create the shortURL
on the body json write
{
"url": "" // here write the longURL bet ""
}Response
{
"short_url": "http://localhost:8080/{SomeNumbers}"
}2- GET /{hash} : redirect to original URL
url-shortener/
├── handlers/
│ └── handlers.go # HTTP handlers (ShortenURL, RedirectURL)
├── models/
│ └── url.go # Request/Response structs
├── router/
│ └── router.go # Route registration + server start
├── storage/
│ └── redis-store.go # Redis connection, SaveURL, GetOriginalURL
├── go.mod
└── main.go
Frontend is completely vibe coded using opencode zen free models MiMo v2.5 high
it also modified the router/router.go to connect the front-end
this part is vibecoded
http.HandleFunc("/app/", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "frontend/index.html")
})
http.HandleFunc("/app", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/app/", http.StatusTemporaryRedirect)
})
