storage

package
v0.0.0-...-8bfd7db Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2022 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

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

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")

	ErrFuzzyMatchFound = errors.New("fuzzy match found")
)

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) Load

func (s *Filesystem) Load(ctx context.Context, rawShort string) (string, error)

func (*Filesystem) SaveName

func (s *Filesystem) SaveName(ctx context.Context, 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(ctx context.Context, rawShort string) (string, error)

func (*Inmem) SaveName

func (s *Inmem) SaveName(ctx context.Context, rawShort string, url string) error

func (*Inmem) Search

func (s *Inmem) Search(ctx context.Context, searchTerm string) ([]SearchResult, error)

func (*Inmem) String

func (s *Inmem) String() string

func (*Inmem) TopNForPeriod

func (s *Inmem) TopNForPeriod(ctx context.Context, n int, days int) ([]TopNResult, error)

type NamedStorage

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

type Postgres

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

func NewPostgres

func NewPostgres(connectURL string) (*Postgres, error)

func (*Postgres) Load

func (p *Postgres) Load(ctx context.Context, rawShort string) (string, error)

func (*Postgres) SaveName

func (p *Postgres) SaveName(ctx context.Context, rawShort string, url string) error

func (*Postgres) Search

func (p *Postgres) Search(ctx context.Context, searchTerm string) ([]SearchResult, error)

func (*Postgres) TopNForPeriod

func (p *Postgres) TopNForPeriod(ctx context.Context, n int, days int) ([]TopNResult, 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(ctx context.Context, short string) (string, error)

func (Regex) SaveName

func (r Regex) SaveName(ctx context.Context, short string, long 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(ctx context.Context, rawShort string) (string, error)

func (*S3) SaveName

func (s *S3) SaveName(ctx context.Context, rawShort string, url string) error

type SearchResult

type SearchResult struct {
	Link string
	URL  string
}

type SearchableStorage

type SearchableStorage interface {
	Storage
	// Search takes a search term and returns a number of possible shorts
	Search(ctx context.Context, searchTerm string) ([]SearchResult, error)
}

type Storage

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

type TopN

type TopN interface {
	Storage
	// TopNForPeriod returns the most visited shorts in the last N days
	TopNForPeriod(ctx context.Context, n int, days int) ([]TopNResult, error)
}

type TopNResult

type TopNResult struct {
	Link     string
	HitCount int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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