storage

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2017 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package storages allows multiple implementation on how to store URLs as shorter names and retrieve them later.

There are currently two types of storage layers, Named and Unnamed. Named storage layers allow the user to provide a short name and a URL Unnamed storage layers only accept the URL to store

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrURLEmpty   = errors.New("provided URL is of zero length")
	ErrShortEmpty = errors.New("provided short name is of zero length")

	ErrURLNotAbsolute = errors.New("provided URL is not an absolute URL")

	ErrShortNotSet     = errors.New("storage layer doens't have a URL for that short code")
	ErrShortExhaustion = errors.New("tried to set short, but unable to find a unique shortname within 10 tries")
)
View Source
var SupportedStorageTypes = make(map[string]interface{})

Functions

func CleanPath

func CleanPath(path string) string

CleanPath removes any path transversal nonsense

func FlattenPath

func FlattenPath(path string, separator string) string

Takes a possibly multilevel path and flattens it by dropping any slashes

Types

type Filesystem

type Filesystem struct {
	Root string
	// contains filtered or unexported fields
}

func NewFilesystem

func NewFilesystem(root string) (*Filesystem, error)

func (*Filesystem) Code

func (s *Filesystem) Code(url string) string

func (*Filesystem) Load

func (s *Filesystem) Load(rawShort string) (string, error)

func (*Filesystem) Save

func (s *Filesystem) Save(url string) (string, error)

func (*Filesystem) SaveName

func (s *Filesystem) SaveName(rawShort, url string) error

type Inmem

type Inmem struct {
	RandLength int
	// contains filtered or unexported fields
}

func NewInmem

func NewInmem(randLength int) (*Inmem, error)

func NewInmemFromMap

func NewInmemFromMap(randLength int, initialShorts map[string]string) (*Inmem, error)

func (*Inmem) Load

func (s *Inmem) Load(rawShort string) (string, error)

func (*Inmem) Save

func (s *Inmem) Save(url string) (string, error)

func (*Inmem) SaveName

func (s *Inmem) SaveName(rawShort string, url string) error

func (Inmem) String

func (s Inmem) String() string

type NamedStorage

type NamedStorage interface {
	Storage
	// SaveName takes a short and a url and saves the name to use for saving a url
	SaveName(short string, url string) error
}

type Regex

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

func NewRegexFromList

func NewRegexFromList(redirects map[string]string) (*Regex, error)

func (Regex) Load

func (r Regex) Load(short string) (string, error)

func (Regex) SaveName

func (r Regex) SaveName(short string, long string) (string, error)

type S3

type S3 struct {
	Client     *s3.S3
	BucketName string
	// contains filtered or unexported fields
}

func NewS3

func NewS3(awsSession *session.Session, bucketName string) (*S3, error)

func (*S3) Load

func (s *S3) Load(rawShort string) (string, error)

func (*S3) Save

func (s *S3) Save(url string) (string, error)

func (*S3) SaveName

func (s *S3) SaveName(rawShort string, url string) error

type Storage

type Storage interface {
	// Load(string) takes a short URL and returns the original full URL by retrieving it from storage
	Load(short string) (string, error)
}

type UnnamedStorage

type UnnamedStorage interface {
	Storage
	// Save(string) takes a full URL and returns the short URL after saving it to storage
	Save(url string) (string, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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