How suraj-kumal/very-short works
This is a Go URL shortener. Users submit long URLs through the web UI or POST endpoint, receive a short link, and later use its code to redirect to the original URL. The runtime also provides expiration and error handling, static pages, concurrency limiting, cache warming, and background access-time synchronization. The README documents several flows whose handler and cache implementations were not excerpted; those links are attributed to the README rather than presented as inspected call details.
Main entry points: main.go Server bootstrap · routes.go Route registration · handlers.go Request handlers · cache.go LRU redirect cache
Components 17
HTTP runtime
- Server bootstrap
cmd/api/main.go - Route registration
internal/handlers/routes.go - Request handlers
internal/handlers/handlers.go - Concurrency limiter
internal/middleware/concurrencylimit.go - Static web pages
static/index.html - Expired and missing pages
static/410.html - Long URL page
static/long.html
Link lifecycle
- Short-code encoding
internal/encode/encode.go
Storage and cache
- URL record operations
internal/database/url.go - MySQL connection
internal/database/database.go - MySQL database
- LRU redirect cache
internal/cache/cache.go - Hot URL loading
internal/database/accesstime.go - Access-time updates
internal/database/accesstime.go
Runtime coordination
- Runtime configuration
internal/config/config.go - Sync coordination
internal/timesync/timesync.go
Other components
- Browser or client
Connections 22
- Browser or client → Route registration: sends requests
README.md - Server bootstrap → Runtime configuration: loads settings
cmd/api/main.go - Server bootstrap → MySQL connection: opens database
cmd/api/main.go - MySQL connection → MySQL database: connects to
internal/database/database.go - Server bootstrap → Hot URL loading: loads hot links
cmd/api/main.go - Hot URL loading → MySQL database: reads records
internal/database/accesstime.go - Server bootstrap → LRU redirect cache: warms cache
cmd/api/main.go - Server bootstrap → Sync coordination: initializes sync
cmd/api/main.go - Server bootstrap → Request handlers: configures handlers
cmd/api/main.go - Server bootstrap → Route registration: registers routes
cmd/api/main.go - Route registration → Request handlers: dispatches requests
internal/handlers/routes.go - Route registration → Concurrency limiter: limits redirects
internal/handlers/routes.go - Route registration → Static web pages: serves assets
internal/handlers/routes.go - Request handlers → Short-code encoding: generates codes
README.md - Request handlers → URL record operations: stores and looks up
README.md - Request handlers → LRU redirect cache: checks redirects
README.md - URL record operations → MySQL database: persists links
README.md - Request handlers → Expired and missing pages: returns error pages
README.md - Route registration → Long URL page: serves long page
internal/handlers/routes.go - Sync coordination → Access-time updates: coordinates updates
- Access-time updates → MySQL database: writes timestamps
internal/database/accesstime.go - LRU redirect cache → Access-time updates: synchronizes access times
README.md