linker

package
v0.0.0-...-8381eac Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2019 License: AGPL-3.0 Imports: 2 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LinkGuard

type LinkGuard interface {
	Allowed(url *url.URL) bool
}

A LinkGuard determines if a URL is allowed to be shortened

type LinkMapper

type LinkMapper interface {
	Map(link *url.URL) (string, error)
}

LinkMapper generates IDs from URLs

type LinkRepository

type LinkRepository interface {
	Get(id string) (*url.URL, error)
	Set(id string, url *url.URL) error
}

A LinkRepository persists ID <=> URL pairs

type LinkShortener

type LinkShortener struct {
	// contains filtered or unexported fields
}

A LinkShortener turns fully-qualified URLS into shorter IDs, and back again

func Make

func Make(guard LinkGuard, mapper LinkMapper, repo LinkRepository) *LinkShortener

Make a default shortener with passed implementations

func (*LinkShortener) Allowed

func (repo *LinkShortener) Allowed(link *url.URL) bool

Allowed returns true if the link is allowed to be shortened

func (*LinkShortener) Expand

func (repo *LinkShortener) Expand(id string) (*url.URL, error)

Expand a shorter ID to a long URL

func (*LinkShortener) Shorten

func (repo *LinkShortener) Shorten(link *url.URL) (string, error)

Shorten a long URL to a shorter ID

Directories

Path Synopsis
guard
mapper
repo

Jump to

Keyboard shortcuts

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