Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go URL Shortener/Redirector Service

This Go package implements a simple HTTP URL shortener/redirector service. My goal with this package was to learn how to create HTTP server in Go that listens for requests on specific paths and redirects them to corresponding target URLs.

A key feature I wanted to implement was to add an ability to load URL mappings from multiple sources and chain the handlers together using a fallback mechanism.

The service works by chaining several http.Handler implementations together. When a request comes in:

  1. Database Check (DBHandler): It first queries the SQLite database (urls.db) to see if the requested path exists in the urls table.
  2. JSON Check (JSONHandler): If the path wasn't found in the DB, applications checks if the path exists in the mappings parsed from the provided JSON data.
  3. YAML Check (YAMLHandler): If the path wasn't found in JSON, applications checks the mappings parsed from the provided YAML data.
  4. Map Check (MapHandler): If the path wasn't found in YAML, applications checks the hardcoded Go map.
  5. Base Mux: Finally, if the path hasn't been matched by any of the redirect handlers, the base http.ServeMux handles the request.

Routes Handled by Forwarder

Any path not listed above responds directly with the text Hello, world!

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages