storage

package
v0.0.0-...-01bad0f Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package storage provides an interface that can be used to connect to various ways that links can be stored and retrieved. It also stores common variables and parameters that are expected to be used across the store implementations.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound           = errors.New("input url not found")
	ErrStorageSetupFailed = errors.New("storage setup failed")
	ErrReadOnlyStorage    = errors.New("storage is read only")
	ErrFailed             = errors.New("storage implementation failed")
	ErrCorrupt            = errors.New("the data returned by the storage is invalid")
	ErrUnauthorized       = errors.New("you are not the owner of this record")
)

Err* are common errors that the storage implementations will return.

Functions

This section is empty.

Types

type Authenticator

type Authenticator interface {
	Owns(ctx context.Context, u *url.URL) bool
}

Authenticator is an extension to the storage interface that allows verifying whether a given user is the canonical owner of a given URL.

Expects to be supplied with a context with the agent stored at the appropriate key. Returns false in the case the user doesn't own the request, or the request cannot be authenticated (e.g. agent is missing)

type CtxKey

type CtxKey string

CtxKey is a type designed to allow delimiting key/value pairs

const (
	// CtxKeyAgent is the context address at which the owner will be found, if there is one.
	CtxKeyAgent CtxKey = "agent"
)

type Storer

type Storer interface {
	// Get a URL, given a supplied shortlink.
	Get(ctx context.Context, url *url.URL) (*url.URL, error)

	// Store a map between a shortlink and the destination.
	Put(ctx context.Context, from *url.URL, to *url.URL) error
}

Storer is the interface that retrieves links supplied to it. Methods are named after the RESTful HTTP verbs, as the meanings are semantically similar.

Directories

Path Synopsis
Package boltdb implements storage based on the BoltDB database, backed by the filesystem.
Package boltdb implements storage based on the BoltDB database, backed by the filesystem.
Package di provides a mechanism to select storage providers.
Package di provides a mechanism to select storage providers.
Package firestore implements a storage layer with Google cloud firestore.
Package firestore implements a storage layer with Google cloud firestore.
Package memory stores the entire data set in memory.
Package memory stores the entire data set in memory.
Package test provides a storage implementation designed explicitly for testing
Package test provides a storage implementation designed explicitly for testing
Package yaml provides a read only storage implementation which sources its URLs from a YAML file.
Package yaml provides a read only storage implementation which sources its URLs from a YAML file.

Jump to

Keyboard shortcuts

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