handlers

package
v0.0.0-...-2e5c2e0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2021 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hello

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

Types

type Database

type Database interface {
	Set(ctx context.Context, key, value string) error
	Get(ctx context.Context, key string) (string, error)
}

Database describes a data store used by Shortener to store shortened URLs data

type Shortner

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

Shortener provides http.HandlerFunc methods to save and get shortened URLs

func New

func New(db Database, uuidFunc func() string) Shortner

New initialises and returns a new Sortener

func (Shortner) GetURL

func (s Shortner) GetURL(w http.ResponseWriter, r *http.Request)

GetURL reads the `to` query parameter, looks it up on Database if it finds a URL for it, the response is a temporary redirect to this URL Exmaple: www.example.com/go?to=uuidv4

func (Shortner) SaveURL

func (s Shortner) SaveURL(w http.ResponseWriter, r *http.Request)

SaveURL reads the `url` query string, generates a token for it and saves them using a Database. Example: www.example.com/some-path?url=https://tiago.life

Jump to

Keyboard shortcuts

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