urlshort

package
v0.0.0-...-0fb2704 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

README

URL Shortener

Details

An http.Handler looks at the path of any incoming web request and determine if it should redirect the user to a new page.

For instance, if we have a redirect setup for /dogs to https://www.somesite.com/a-story-about-dogs we would look for any incoming web requests with the path /dogs and redirect them.

The MapHandler function uses a predefined map to map the path to the corresponding URL.

The YAMLHandler and JSONHandler functions take a file (-file <filename>) and parses the file for the url paths ans corresponding URLs to redirect users as appropriate. The file parsed depends on the extension of the provided file *.ext.

The DBHandler function checks the database for the provided paths and redirects as appropriate. Set the flag -newdb true to initialize a new database.

Usage

go run main/main.go -newdb true

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DBHandler

func DBHandler(db *sql.DB, fallback http.Handler) http.HandlerFunc

DBHandler will query the database for provided path and redirect the user to the URL corresponding to the shortcut If the path is not found in the database, then the fallback http.Handler will be called instead.

func JSONHandler

func JSONHandler(json []byte, fallback http.Handler) (http.HandlerFunc, error)

func MapHandler

func MapHandler(pathsToUrls map[string]string, fallback http.Handler) http.HandlerFunc

MapHandler will return an http.HandlerFunc that will attempt to map any paths to their corresponding URL If the path is not provided in the map, then the fallback http.Handler will be called instead.

func YAMLHandler

func YAMLHandler(yml []byte, fallback http.Handler) (http.HandlerFunc, error)

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL