shortlink

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2017 License: GPL-3.0 Imports: 7 Imported by: 2

Documentation

Overview

Package shortlink is a very simple link shortener.

Index

Constants

This section is empty.

Variables

View Source
var DbFile = "links.db"

DbFile is the filename of the bolt db file

View Source
var URIPrefix = "/s"

URIPrefix is the prefix for the router

Functions

func AddRoute

func AddRoute(r *mux.Router) *mux.Router

AddRoute adds the redirect route to a mux router. The logic here is that just the id is part of the url after the URIPrefix

func GetID

func GetID(url string) (int, error)

GetID returns a unique id to a given url. If a url don't have a ID a new is created.

func GetShort

func GetShort(url string) (string, error)

GetShort returns the short url for a url

func Redirect

func Redirect(w http.ResponseWriter, r *http.Request)

Redirect is the handler, which needs the id inside the mux.Route

Types

type Link struct {
	ID  int    `storm:"id,increment"`
	URL string `storm:"unique"`
}

Link represents a link with an id

Jump to

Keyboard shortcuts

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